- Home /
Can I select an object in the hierarchy with code while the game is running?
I have to select an instantiated gameobject with the mouse but the game is running. The mouse needs to stay in a certain place in the game for navigation and player position
Answer by robertbu · Apr 15, 2014 at 04:39 AM
Assuming you are talking about inside the Unity Editor, then yes you can. Example script that select the object it is attached to when the space bar is hit:
#pragma strict
import UnityEditor;
function Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Selection.activeObject = gameObject;
}
}
@robertbu!, You are the man. Thanks.! One liner: Selection.activeObject = gameObject; SOLUTION Give yourself a raise, have a beer, put your feet up!
Your answer
Follow this Question
Related Questions
when mouse is on a object do this 2 Answers
trying to move an object with the mouse 1 Answer
Destroy object with more clicks depending on Scale? 0 Answers
Mouse drag and drop a gameobject javascript 2 Answers
Trying to make a simple inventory: 0 Answers