- Home /
Poster found the problem - see comments
Anyone help with my switch statement?
Hey guys, having a little trouble with my switch statement. I am trying to activate/deactivate a gameObject dependent on a counters variable. At the moment it is not hiding the object when the counter equals the correct variable. He's the script:
 // weapon variables for switch
 
 var weapon : int = 0;
 
 var sword : Transform;
 
 
 function Update () {
 
 // Switch statement ( counter )
 
 
 if (Input.GetKeyDown(KeyCode.Tab) && weapon < 1)
 {
           weapon++;
 }
     else if (Input.GetKeyDown(KeyCode.Tab) && weapon >= 1)
     {
         weapon = 0;
         }
 
 }
 
 // Switch function to enable weapon switching.
 
    switch ( weapon )
 {
     case 0:
          if (weapon == 0)
          sword.renderer.enabled = true;
          break;
          
     case 1:
          if (weapon == 1)
          sword.renderer.enabled = false;
          break;
          } 
 
 
 
  
I have deleted the irrelevant code to make it easier for you guys to read. There are no syntax errors (the script runs fine just doesn't do as I say :P ). I have assigned the game object in the inspector to the sword variable. What am I doing wrong :o
Feel like a complete idiot, wasn't in my update function. Apologies for wasting time.
Follow this Question
Related Questions
Stop player being launched on switch weapons 1 Answer
What is wrong with my c# switch statement? 1 Answer
Weapon swap help 1 Answer
Weapon Switching 1 Answer
Using the StartsWith function in a Switch Case Statement 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                