- Home /
check if Go.tag is this instance of the object
//left click Unit, Select it
if (Input.GetMouseButtonDown(0) && object.tag == "Unit"){
//check it is me???
selected = true;
}
at the moment all instances get selected.
*NB : object is set via Raycast from screen to mouse position.
Answer by save · Oct 01, 2011 at 08:53 PM
My best guess is that you should make one or more variables private. The actual selected object should be a static variable which makes a reference to a GameObject.
static var selectedObject : GameObject;
if (selectedObject==this.gameObject)
An even better approach would be to have an overhead which checks if something is selected, then takes over parts of the GameObjects regular script. If you have lots of objects checking "if I am this" you'll notice a slight impact on performance. But instead letting one function control that part for the selected object will make a more clean and effective pipeline.
Your answer
Follow this Question
Related Questions
Physics.CheckSphere with tag 1 Answer
Tiny tag changing and checking problem 2 Answers
How to check if all clones of the same tag are destroyed? 0 Answers
Check if there is a child with a tag? (multiple children but each diff tag) 1 Answer
Why cant my FindGameObjectsWithTag function find any objects? 2 Answers