Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Javascript Distance Check Not Working

$
0
0
I'm working on a script which means that if a player presses the 'e' key when close to another player, they will attack. Although I can see in the inspector that the variable 'distance1' is working and changing as the characters move, I don't get any of my Debug.Log statements and pressing the e key does nothing. I'm guessing this means that the statement 'if(distance1 < 2)' is never fulfilled. Any ideas why this could be? Thanks. var distance1: float; function Update () { var manager = GameObject.Find("NetworkManager"); var script = manager.GetComponent(NetworkManagerScript); var Player1 = script.Player1; distance1= Vector3.Distance(gameObject.transform.position, Player1.transform.position); if(distance1 < 2){ Debug.Log("Close"); if(Input.GetKeyDown("e")){ Debug.Log("Dead"); Destroy(Player1); } } }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>