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 thecoolracer · Jan 24, 2013 at 01:57 PM · triggerplayerontriggerenter

OnTriggerStay and OnTriggerEnter won't react when the player enters them.

I have a script which checks if the player has entered the trigger and if it is then ask if he wants to buy ammo, the strange thing is - the trigger simply doesn't work while a similar method works for zombies.

Here is the code:

 var Bought : boolean = false;
 var LAAS : boolean = false;
 
 function OnTiggerStay (collision : Collider) {
     if(collision.tag == "Player") {
         LAAS = true;
     }
 }
 
 function OnTriggerExit (collision : Collider) {
     if(collision.tag == "Player") {
         LAAS = false;
     }
 }
 
 function Update () {
     if(LAAS == true) {
         if(Input.GetKey(KeyCode.E)) {
         }
     }
 }
 
 function OnGUI () {
     if (LAAS == true) {
         GUI.Label(Rect (10, 50, 300, 20), "Press E to buy 1 mag for 20 points");
     }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Karsnen_2 · Jan 24, 2013 at 02:37 PM

You have a trigger Enter & Exit.

Now how big is the trigger?

Now with your code, you have not signified the purpose to happen when the player hits the 'e' button. You might have to look into it. Now - Lets consider a scenario which I believe is more relavent to yours.

I am assuming that when the player is inside the collider (which is a trigger), the player has the ability buy stuff. Hence why not make the code like this.

 function OnTriggerStay (collision : Collider) {
     if(collision.tag == "Player")
  {
       if(Input.GetKey(KeyCode.E))]
   {
        // add your relevant code here. 
        }
     }
 }


Let me know, if it works.

Later.

Comment
Add comment · Show 5 · 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 thecoolracer · Jan 24, 2013 at 03:31 PM 0
Share

This is a draft code. The trigger is larger than the player, it is huge. There is no action for E yet. I want it to show the player a prompt if he wants to buy a new weapon. If he presses E while the prompt is showing, score will be deducted and he will get a new gun. I know ho to make that - the problem is that it doesn't even detect that the player is there.

avatar image thecoolracer · Jan 25, 2013 at 05:24 AM 0
Share

It doesn't work :(

avatar image Karsnen_2 · Jan 28, 2013 at 02:58 PM 0
Share

What do you mean when you say there is no action for 'E' yet?

To have a pop, what you have to do is create a button pop-up with a boolean value under the hood. You need to use the boolean value to trigger the event. after a collision, you have a pop up. This pop-up will send two events a) true b) false. If it is true the you buy the weapon.

So on a large view, you do not buy the weapon when you press 'e'. The weapon is bought by the event that is sent.

avatar image thecoolracer · Jan 29, 2013 at 12:52 PM 0
Share

I will make the code, what I am concerned about that I used the exact same system as in the code for my other game and it works fine. I want to know why the trigger doesn't detect that the player is in it.

avatar image Karsnen_2 · Jan 29, 2013 at 10:19 PM 0
Share

Coolracer: I think you might have to check this chart.

Check the chart at the bottom of the page.

http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html

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

10 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

Related Questions

Key and Door Tutorial Help? 2 Answers

Problem with OnTriggerEnter() 1 Answer

Best practice for OnTriggerEnter detection 1 Answer

Do a collider only with certain taged objects 2 Answers

Getting My FPS Controller To Play An Animation After A Trigger Event 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