Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 18, 2012 at 05:55 PM by whydoidoit for the following reason:

Poster found the problem - see comments

avatar image
0
Question by Nercoe · Oct 18, 2012 at 05:49 PM · weaponswitchstatement

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nercoe · Oct 18, 2012 at 05:51 PM 0
Share

Feel like a complete idiot, wasn't in my update function. Apologies for wasting time.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges