Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

aradox

Member
  • Content Count

    140
  • Joined

  • Last visited

Community Reputation

3 Neutral

4 Followers

About aradox

  • Rank
    Member
  • Birthday 05/07/1998

Profile Information

  • Gender
    Not Telling
  1. Hey guys, i have trouble with getting my units to move(it is an rts style game). the problem is that when i try to send my unity somewhere my code does not return a moveToDestination so in my unit script the units dont know where the destination is. I would appreciate it if you could make sugestiona how to improve my code so that i works. this script is my my main camera and controls the location of the destination.( atleast it should) using UnityEngine; using System.Collections; using System.Collections.Generic; public class CameraOperator : MonoBehaviour { public Texture2D selectHightlight = null; public static Rect selection = new Rect(0,0,0,0); private Vector3 startClick = -Vector3.one; private static Vector3 moveToDestination = Vector3.zero; private static List<string> passables = new List<string>() { "Floor" }; private void Update () { CheckCamera (); CleanUp (); } private void CheckCamera() { if (Input.GetMouseButtonDown (0)) startClick = Input.mousePosition; else if (Input.GetMouseButtonUp (0)) startClick = -Vector3.one; if (Input.GetMouseButton (0)) { selection = new Rect(startClick.x, InvertMouseY(startClick.y), Input.mousePosition.x - startClick.x,InvertMouseY(Input.mousePosition.y) - InvertMouseY(startClick.y)); if(selection.width < 0){ selection.x += selection.width; selection.width = -selection.width; } if(selection.height < 0){ selection.y += selection.height; selection.height = -selection.height; } } } private void OnGUI (){ if (startClick != -Vector3.one) { GUI.color = new Color(1,1,1,0.5f); GUI.DrawTexture(selection, selectHightlight); } } public static float InvertMouseY(float y){ return Screen.height -y; } private void CleanUp(){ if(!Input.GetMouseButtonUp(1)) moveToDestination = Vector3.zero; } public static Vector3 GetDestination(){ if (moveToDestination == Vector3.zero) { RaycastHit hit; Ray r = Camera.main.ScreenPointToRay(Input.mousePosition); if(Physics.Raycast(r, out hit)){ while(!passables.Contains(hit.transform.gameObject.name)){ if(!Physics.Raycast(hit.point + r.direction*0.1f , r.direction, out hit)) break; } } if(hit.transform != null) moveToDestination = hit.point; } return moveToDestination; } } this is my unit script using UnityEngine; using System.Collections; public class Unit : MonoBehaviour { public bool selected = false; private Vector3 moveToDest = Vector3.zero; public float floorOffset = 1; public float speed = 5; public float stopDistanceOffset = 0.5f; void Update () { if (GetComponent<Renderer>().isVisible && Input.GetMouseButtonUp (0)) { Vector3 camPos = Camera.main.WorldToScreenPoint(transform.position); camPos.y = CameraOperator.InvertMouseY(camPos.y); selected = CameraOperator.selection.Contains(camPos); if (selected) { GetComponent<Renderer>().material.color = Color.red; } else GetComponent<Renderer>().material.color = Color.white; } if (selected && Input.GetMouseButtonUp (1)) { Vector3 destination = CameraOperator.GetDestination(); if(destination != Vector3.zero){ //gameObject.GetComponent<NavMeshAgent>().SetDestination(destination); moveToDest = destination; moveToDest.y += floorOffset; } } UpdateMove (); } private void UpdateMove(){ if (moveToDest != Vector3.zero && transform.position != moveToDest) { Vector3 direction = (moveToDest - transform.position).normalized; direction.y = 0; transform.GetComponent<Rigidbody>().velocity = direction * speed; if(Vector3.Distance(transform.position, moveToDest) < stopDistanceOffset){ moveToDest = Vector3.zero; } else transform.GetComponent<Rigidbody>().velocity = Vector3.zero; } } }
  2. your design won't work in reality because you need to ionize the sodium, this can be done by pouring water over the sodium. Na = Sodium, Cl = Cloride Na + H2O ->> Na^+ + H20^ ∂ - 2Na^+ + Cl2^- ->> 2NaCl + Heat you're welcome i am not 100% sure if this is right but it is a step in the right direction. (I'm 90% sure)
  3. "infra-green", as infrared has a green color so infragreen must have a red color
  4. aradox

    Performance

    i didn't know how to explain it
  5. aradox

    Performance

    Hey, i have a question: if I have a gun and the magazine and the gun are the same object will be less heavy on the preformance than when i have 2 separate objects e.g. the gun and the mag are different objects so i can animate them easier???? please help out thanks in advance
  6. here you go http://forum.unity3d.com/threads/m2hpatcher.62326/
  7. is the object you're trying to launch/push a rigidbody? (does the object have the rigidboy component)
  8. maybe you can change the material the play is made of and make multiple particle system cloaking the player
  9. hey guys i have this problem i can't open the asset store in unity because when i do the screen turns white like this also i get a white screen when i go to unity websites like the unity forum (forum.unity3d.com) is there any solution to this problem? please help me because i need to use the asset store for my project. thanks in advance
  10. aradox

    Network.Destroy

    using UnityEngine; using System.Collections; public class NetworkManager : MonoBehaviour { public GameObject playerPrefab; private const string typeName = "Still"; private const string gameName = "Game"; private HostData[] hostList; void Start(){ RefreshHostList(); } private void StartServer(){ Network.InitializeServer(5,25000,!Network.HavePublicAddress()); MasterServer.RegisterHost(typeName,gameName); } void OnServerInitialized(){ SpawnPlayer(); } void OnConnectedToServer(){ SpawnPlayer(); } void OnGUI(){ if(!Network.isClient && !Network.isServer){ if(GUI.Button(new Rect (100,100,250,100), "Start Server")) StartServer(); if(GUI.Button(new Rect (100,250,250,100), "Refresh server list")) RefreshHostList(); if(hostList != null){ for(int i = 0; i < hostList.Length; i++){ if(GUI.Button(new Rect (400,100 + (100*i),250,100), hostList[i].gameName)) JoinServer(hostList[i]); } } } if(GUI.Button(new Rect(100, 100, 100, 50), "Disconnect")){ MasterServer.UnregisterHost(); Network.Disconnect(); } } void OnNetworkInstantiate(NetworkMessageInfo info) { Debug.Log(networkView.viewID + "spawned"); if (Network.isServer) { Network.RemoveRPCs(networkView.viewID); Network.Destroy(gameObject); } } private void RefreshHostList(){ MasterServer.RequestHostList(typeName); } void OnMasterServerEvent(MasterServerEvent msEvent){ if(msEvent == MasterServerEvent.HostListReceived) hostList = MasterServer.PollHostList(); } private void JoinServer(HostData hostData){ Network.Connect(hostData); } private void SpawnPlayer(){ Network.Instantiate(playerPrefab, new Vector3(-1f,10f,12f), Quaternion.identity,0); } void OnPlayerDisconnected(NetworkPlayer player){ Debug.Log("Clean up after player " + player); Network.RemoveRPCs(player); Network.DestroyPlayerObjects(player); } } this is what happens when i click this happens https://www.dropbox.com/s/cbvc40dbcz3ylhf/unity%203d%20armed%20need%20help.JPG
  11. aradox

    time interval in Ai

    I am no Javascript expert but i thing of you did something like this it would work var moveSpeed : float = 2; var rotSpeed : float = 10; var moveDir : int = 1; var haswalked : bool = flase; internal var animator : Animator; enum status { walking, idle } var state : status; function Start () { animator = GetComponent(Animator); } function Update(){ if(haswalked = false){ if(state == state.walking){ moveSpeed = 2; rotSpeed=10; if(!Physics.Raycast(transform.position, transform.forward, 5)) { transform.Translate(Vector3.forward * moveSpeed * Time.smoothDeltaTime); } else{ if(Physics.Raycast(transform.position, - transform.right, 1)) { moveDir = 1;} else if(Physics.Raycast(transform.position, transform.right, 1)) { moveDir = -1;} transform.Rotate(Vector3.up, 90 * rotSpeed * Time.smoothDeltaTime * moveDir); haswalker = true; } } } if(haswalked = true){ yield WaitForSeconds (5); if(state == state.idle){ animator.SetBool("idle",true); animator.SetBool("walking",false); } } }
  12. aradox

    Network.Destroy

    nope didnt work but thnx for trying
  13. aradox

    Network.Destroy

    can somebody please help me trying to destroy a object when i am disconnected by the network. [RPC] private void SpawnPlayer(){ Network.Instantiate(playerPrefab, new Vector3(-1f,10f,12f), Quaternion.identity,0); } void OnPlayerDisconnected(NetworkPlayer player){ Network.RemoveRPCs(player); Network.Destroy(player); } this is the code i made but doesnt work
  14. i already did i reinstalled unity
×
×
  • Create New...