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 Daniel G · Jul 16, 2013 at 12:22 AM · javascriptontriggerstaybooleans

OnTriggerStay Not Working, JavaScript Help Needed

Hello, I know im making a leap in logic somewhere, But i cant find it.

What i want to do, 1. Find if the object with the LevelSelectA1 Script is touching and STAYING in the trigger, (Trigger is a seperate GameObj and yes the trigger checkbox is checked) 2. IF the Obj is triggering the trigger, Then a boolean is set true, if it exits the boolean is false. 3. IF its true and if it is clicked it plays an iTween animation! And a Select sound

Refresh me, if im wrong but don't you set up the OTHER collider with the trigger box checked? Am I possibly missing anything?

Here is the code:

 var initialColor:Color;
 var SelectColor:Color;
 var SelectSound : AudioClip;
 var FingerOverSound : AudioClip;
 var menuCam : GameObject;
 var A1 : GameObject;
 var ReadyPOS : boolean = false;
 
 
 function Start()
 {
     initialColor = renderer.material.color;
 }
 
 
 function OnMouseExit(){
 
     renderer.material.color = initialColor;    
 }
 
 function OnMouseOver(){
     if (ReadyPOS) {
         renderer.material.color = SelectColor;
     }    
 }
 
 function OnMouseEnter () {
     if (ReadyPOS) {
         audio.clip = FingerOverSound;
         audio.Play();
     }
 }
 
 function OnMouseDown () {
     if (ReadyPOS) {
         audio.clip = SelectSound;
         audio.Play();
         iTweenEvent.GetEvent(menuCam, "AreaSelectToLevelSelect").Play();
         iTweenEvent.GetEvent(A1, "DiamondMoveToLevelSelectFromAreaSelect").Play();
     }
 }
 
 
 function OnTriggerStay (other : Collider) {
        ReadyPOS = true;
     }
 function OnTriggerExit (other : Collider) {
        ReadyPOS = false;
     }

Thanks for the Help! Daniel

Comment
Add comment · Show 5
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 AndyMartin458 · Jul 16, 2013 at 12:52 AM 0
Share

What is the nature of the problem you're experiencing? If you put Debug.Log("Trigger stay"); in the OnTriggerStay function, is it ever being called?

avatar image Daniel G · Jul 16, 2013 at 12:57 AM 0
Share

@Andy$$anonymous$$artin458 No its not, BUT the rest of the code works because if i manually set the boolean to true in the inspector it works, So Whats not working here is the OnTriggerStay, Also Other just stands for any collider correct? Im going to try on collision enter too.

avatar image Daniel G · Jul 16, 2013 at 01:02 AM 0
Share

This is not working either,

 function OnCollisionEnter (collision : Collision) {
        ReadyPOS = true;
        Debug.Log ("Entered");
     }
 function OnCollsionExit (collision : Collision) {
        ReadyPOS = false;
        Debug.Log ("Exited");
     }
avatar image AndyMartin458 · Jul 16, 2013 at 01:05 AM 0
Share

yes, other is any collider that touches your object.

avatar image Daniel G · Jul 16, 2013 at 01:08 AM 0
Share

@Andy$$anonymous$$artin458 I'm not getting any luck with collision enter and exit either, I have done this before, Cant seem to figure out what I'm $$anonymous$$issing? So weird! Any ideas?

1 Reply

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

Answer by AndyMartin458 · Jul 16, 2013 at 01:06 AM

Did you attach a Rigid Body to the other colliders? One of the colliders have to have a Rigid Body for that function to be called. Probably you should put one on the stationary object.

Update:

What are your objects? If you think of this example. Trigger is on the level, and the collider is a player running around. If your player and the trigger both have colliders, then the OnTriggerStay function still won't be called. You need to go to Component -> Physics -> Rigid Body and add it to the trigger or the player.

Comment
Add comment · Show 9 · 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 Daniel G · Jul 16, 2013 at 01:23 AM 0
Share

@Andy$$anonymous$$artin458 I'm sure that would have stopped it too thank you, But Its still not registering, I am now back to the Trigger enter and this is my set up in detail,

alt text

Am I missing something?

setup.jpg (76.8 kB)
avatar image Daniel G · Jul 16, 2013 at 01:26 AM 0
Share

Yes i did what you said :D Thank you, Still having the issue :P

avatar image AndyMartin458 · Jul 16, 2013 at 01:26 AM 0
Share

@$$anonymous$$_G the Obj With Script that moves into the collider needs to have a collider. Does it have one too?

avatar image Daniel G · Jul 16, 2013 at 01:28 AM 0
Share

@Andy$$anonymous$$artin458 Yes :P Sorry I didn't include that!

avatar image Daniel G · Jul 16, 2013 at 01:41 AM 1
Share

Thank you soooo $$anonymous$$uch sir :D

Show more comments

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

15 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 avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Changing material Color using RBG? 3 Answers

Has anyone got a Toggle key script? 3 Answers

Int and Javascript help 2 Answers

Integer in if statement, scripting help 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