- Home /
Duplicate Question : http://answers.unity3d.com/questions/621401/switching-between-2-states.html
switching between 2 states
private var change: int = 0;
function Start () {
}
function Update () {
Debug.Log (change);
if(Input.GetButtonDown("Jump"))
{
if (change < 1)change ++;
else change = 0;
}
if (change == 0){
if(tag=="Black")renderer.enabled = false;
if(tag=="White")renderer.enabled = true;
}
if (change == 1)
{
if(tag=="Black")renderer.enabled = true;
if(tag=="White")renderer.enabled = false;
}
}
What I am trying to do is have a player switch between two different sets of platforms on the press of the space bar. The problem I have is the collider is still there when the platform render is off. What I think I need to do is turn the gameobjects on and off from a separate gameobject.
Answer by Pecek · Jan 20, 2014 at 06:33 PM
You can disable any component the same way as the renderer(like the collider). http://docs.unity3d.com/Documentation/ScriptReference/Collider-enabled.html
Follow this Question
Related Questions
All the objects in my script choose the same target. 2 Answers
Access a child from the parent or other gameObject. 2 Answers
Is it possible to create a tag programmatically? 5 Answers
Reverse search of GameObject.FindGameObjectsWithTag 1 Answer
Can you change a variable based on the tag of an object? 1 Answer