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 /
avatar image
0
Question by Blink · Mar 26, 2013 at 02:43 PM · taggunactivation

Activating and deactivating problem

I am activating and deactivating my guns on collision to create a weapon pick up feature. For example the Player starts with no gun because they are all deactivated on start, but if he collides with an object with a tag of say UZI that gun will become active, keeping all the other guns deactivated. This doesnt work how I would of thought, instead it only activates the M14 keeping everything else deactivated no matter which tagged object I collide with. I hope you understand my script better than my explanation, hope someone can help.

 var glock : GameObject;
 var UZI : GameObject;
 var G36C : GameObject;
 var M14 : GameObject;
 
 function Start () {
 
 UZI.active = false;
 glock.active = false;
 G36C.active = false;
 M14.active = false;
 }
 
 function OnCollisionEnter(collision: Collision) {
  
 if (collision.gameObject.tag == "UZI");
 
 UZI.active = true;
 glock.active = false;
 G36C.active = false;
 M14.active = false;
 
 
 
  
 if (collision.gameObject.tag == "glock");
 
 UZI.active = false;
 glock.active = true;
 G36C.active = false;
 M14.active = false;
 
 
 
  
 if (collision.gameObject.tag == "G36C");
 
 UZI.active = false;
 glock.active = false;
 G36C.active = true;
 M14.active = false;
 
 
 
  
 if (collision.gameObject.tag == "M14");
 
 UZI.active = false;
 glock.active = false;
 G36C.active = false;
 M14.active = true;
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by whebert · Mar 26, 2013 at 02:50 PM

You need to surround each one of your if statement logic with { }, and not put a semicolon after the if. Like so:

 if (collision.gameObject.tag == "UZI")
 {
    UZI.active = true;
    glock.active = false;
    G36C.active = false;
    M14.active = false;
 }
Comment
Add comment · Show 1 · Share
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 Blink · Mar 26, 2013 at 03:15 PM 0
Share

Works perfectly thanks!

avatar image
1

Answer by ZorNiFieD · Mar 26, 2013 at 02:54 PM

do what whebert said, but also do this:

 UZI.SetActive(true);  // correctly sets object and all subobjects active recursively
 UZI.active = true;  // not correct
Comment
Add comment · Share
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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Gun aim off center 0 Answers

Gun swap through collision 1 Answer

Goes faster when moving to monster's transform 1 Answer

damage cooldown 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