- Home /
Question by
Ghostleg · May 19, 2015 at 10:46 AM ·
c#click objects
Click on GameObject
Hello i'm trying ti make a map editor so i do need to track click's on GameObject to select them. I have wrapper for GameObject so i can load different gameObjects and etc. So i added this to script :
private GameObject obj;
private string obj_name;
private bool targeted;
void Update ()
{
if (Input.GetMouseButtonUp (0)) {
targeted = false;
}
if (Input.GetMouseButtonDown (0))
{
targeted = true;
obj.transform.TransformPoint(Input.mousePosition );
if ( Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow) )
{
obj.transform.Rotate(0,-90,0);
}
}
if (targeted && Input.GetKeyDown (KeyCode.Delete)) {
Destroy(obj);
}
}
But it doesn't work at all. What am i doing wrong ?
Comment
I think you never define obj. You only modify it's transform.
You are not checking if you are clicking on something. You would need to raycast, so you know if the mouse is clicking on anything at all.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer