|
ok its late and it might be because i'm tired that i dont get this but i'm having some trouble with distance detection. i am currently using the mouse look script and "Screen.lockCursor = true;" command to center the mouse. i can set it up so that when i mouse over / aim at the object it changes a color but i want it to change when i am at a certain distance away from the object. this is what i have pieced together from several sources and attempted to add in a distance calculator var vector; function FixedUpdate () { var dist = GameObject.FindWithTag("Player").transform.position - transform.position; dist.y = 0; vector = dist.magnitude; } function OnMouseEnter() { if (vector <= .5 ) { renderer.material.color = Color.black; } else { } } i have a version of my game hosted at my site [http://www.hazardousproductions.net/Testing/Testing.html][1] with this code in there (the look and highlight command) var dist; var vector; function FixedUpdate () { var dist = GameObject.FindWithTag("Player").transform.position - transform.position; dist.y = 0; vector = dist.magnitude; } function OnMouseEnter() { renderer.material.color = Color.black; } function OnMouseExit() { renderer.material.color = Color.black; } thanks in advance note: in the game use the mouse to look around w a s d or arrow keys to walk around and the level the problem is on is level 1
(comments are locked)
|
|
i was over thinking the whole thing lol. i used raycast to detect the distance from the object and ditched the mouseenter idea because it wasnt working out correctly. my somewhat final code
(comments are locked)
|
|
Raycast should do the trick:
(comments are locked)
|
