- Home /
How to active/deactive gameobject?
hi i make a fps game and i want to deactive/active the scope (gameobject) i have try the .active thing but i dont khow how to do it. here is the script
var ScopeObject : GameObject;
function Start() {
ScopeObject.active = true;
}
if(Input.GetButtonDown("e"));
function Update(){
ScopeObject.active = false;
}
Answer by fafase · Aug 02, 2012 at 09:36 PM
var ScopeObject : GameObject;
function Start() {
ScopeObject.active = true;
}
function Update(){
if(Input.GetButtonDown("e"))ScopeObject.active = false;
}
Input needs be in Update and has no ; at the end. Also, you need to drag the object in the Inpsector in the ScopeObject slot or use
function Start(){
ScopeObject = GameObject.Find("Name of the scope object");
}
Your answer
Follow this Question
Related Questions
How do I set a reference in the inspector 1 Answer
How to disable gameobjects in code? 4 Answers
How to make an open and close box?,How to make open and close a box? 0 Answers
If you disable a gameobject, does an InvokeRepeating loop end or pause? 3 Answers
GameObject.setActive(bool) is not activating my gameObject 1 Answer