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
1
Question by Orloffyeah · Jan 13, 2013 at 02:41 AM · triggercomponentgundetection

Detect Trigger Enter for One Game Object

Hi, I have been working on a trigger detection system, in the moment that the player passes through a trigger his gun gets activated and it works fine, but when I have to players in scene both of the player get their guns active, even if just one of them enters the trigger. How can I make so that the trigger only activate the components of the player that passes through it?

Trigger Script:

 function OnTriggerEnter(col : Collider)
 {
 
     if (col.gameObject.name == "Minigun_Trigger")
     {
         Gun_Script.minigunUnlocked = true;
         RocketLauncher.rocketsUnlocked = false;
         SmokeCreator.smokeUnlocked = false;
         yield WaitForSeconds(40);
         Gun_Script.minigunUnlocked = false;
         
     }
     
 }
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 Fattie · Jan 13, 2013 at 10:22 AM 0
Share

do not use static variables

2 Replies

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

Answer by whydoidoit · Jan 13, 2013 at 02:51 AM

You need to not use static variables - statics are for advanced use only and always cause this kind of behaviour if you use them without careful planning. (See this article)

In your case you will need a way of accessing the Gun_Script, RocketLauncher etc for the particular player - if they are scripts on the player (and the script you posted is attached to the player) then you should just be able to make them non-static and then get access using GetComponent.

   GetComponent(Gun_Script).minigunUnlocked = true;
Comment
Add comment · Show 2 · 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 Orloffyeah · Jan 13, 2013 at 09:18 PM 0
Share

Thanks, it worked, I always forgot to not use static variables. :)

avatar image Orloffyeah · Jan 13, 2013 at 11:29 PM 0
Share

Now I have to make a new questions so that it works for multiple children :D

avatar image
1

Answer by Piflik · Jan 13, 2013 at 02:54 AM

Don't use static variables to unlock the weapons. These belong to the class, not to the individual members of that class, and thus there is only ever one single instance of that variable.

Use public variables and access them via GetComponent();

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

11 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

Related Questions

how can I trigger my animation through script? 1 Answer

How to get the right Collider component? 2 Answers

How can i make my gun have two different animations 0 Answers

Can't click gameobject when over another trigger? 1 Answer

OnTriggerEnter2D not Working 0 Answers


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