- Home /
Selecting and unselecting objects with raycast
I made this in order to select objects :
var ray : Ray = camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
//Debug.DrawRay (ray.origin, ray.direction * 100, Color.yellow);
if (Physics.Raycast (ray.origin, ray.direction, hit, 100))
{
if(hit.collider.tag == "Object")
{
print ("Here is an object!");
}
var object : GameObject = hit.collider.gameObject;
var myAI1 : MyAI1 = object.GetComponent(MyAI1);
//we change the color
myAI1.ChangeColor();
}
It works fine, and i know when the mouse goes over the object, but how could I do to know when the object is being unselected, when the mouse is leaving it?
thank you for all the help!
if you dont have too many objects in your scene... you could run scripts on those objects... just a simple timer... that gets setup in your ChangeColor() e.g. timer =2 then each frame, if (timer > 0 ) subtract 1 from timer; if timer==0; then delelected;
Follow this Question
Related Questions
Selecting and unselecting objects with raycast 2 Answers
how to put the objects together (javascript) 1 Answer
Hiding and showing multiple objects 1 Answer
Carrying Objects OnMouseOver 0 Answers
Play sound when clicking object 1 Answer