Quantcast
Channel: Answers for "Something like OnTriggerExit for Raycasts?"
Viewing all articles
Browse latest Browse all 4

Answer by V-Jankaitis

$
0
0
void Hit_Target() // put this in update function { Ray ray = Cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.gameObject.GetComponent() != null) // If hit object has needed script (avoid highliting other objects) { if (Target != hit.collider.gameObject) // if I`m not already looking at it { if (Target != null) // if no object selected; { Target.GetComponent().Hit(false); // Reverse the old one back in here } Target = hit.collider.gameObject; // make object my target Target.GetComponent().Hit(true); // call it`s script } } else if (Target != null) // { Target.GetComponent().Hit(false); // Reverse the old one back in here Target = null; } } else if (Target != null) // { Target.GetComponent().Hit(false); // Reverse the old one back in here Target = null; } }

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images