Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Wesley21spelde · May 18, 2014 at 09:20 AM · ontriggerenter

OnTriggerEnter Not working

Hey guys this problem is aboute the function OnTriggerEnter it doesnt work and when i pud it in the Update it works only i need it to work when my player is in the water Collider What did i do wrong??? thanks

 var WaterLevel : float;
 var useGravity: boolean;
 var Player : GameObject;
 var useBlur : boolean;
 var Bubbels : GameObject;
 
 private var defaultFog = RenderSettings.fog;
 private var isUnderwater : boolean;
 private var normalColor : Color;
 private var underwaterColor : Color;
 private var defaultSkybox = RenderSettings.skybox;
 var noSkybox : Material;
 
 function Start () {
     normalColor = new Color (0.5f, 0.5f, 0.5f, 0.5f);
     //0.22f, 0.80f, 0.80f, 0.5f)
     underwaterColor = new Color (0.80f, 0.85f, 0.75f, 0.5f);
     RenderSettings.fog = true;
     Bubbels.active = false;
     camera.GetComponent(Blur).enabled = false;
     camera.GetComponent(Fisheye).enabled = false;
 }
 
 function OnTriggerEnter (Player : Collider){
     if ((transform.position .y < WaterLevel) != isUnderwater) 
     {
          isUnderwater = transform.position.y < WaterLevel;
          if (isUnderwater) SetUnderwater ();
          if (!isUnderwater) SetNormal ();
     }
 } 
 //function Update () {
 //   if ((transform.position .y < WaterLevel) != isUnderwater) 
 //    {
 //         isUnderwater = transform.position.y < WaterLevel;
 //         if (isUnderwater) SetUnderwater ();
 //         if (!isUnderwater) SetNormal ();
 //    }
 //}
 
 function SetUnderwater() 
 {
    //The Bubbels are a particle renderer Attached to The Player
    Bubbels.active = true;
    RenderSettings.fog = true;
    RenderSettings.fogColor = underwaterColor;
    RenderSettings.fogDensity = 0.10f;
    RenderSettings.skybox = noSkybox;
    camera.GetComponent(Blur).enabled = true;
    camera.GetComponent(Fisheye).enabled = true;
 
  }
 
 function SetNormal() 
 {
    Bubbels.active = false;
    RenderSettings.fog = defaultFog;
    RenderSettings.fogColor = normalColor;
    RenderSettings.fogDensity = 0.03f;
    camera.GetComponent(Blur).enabled = false;
    camera.GetComponent(Fisheye).enabled = false;
 }
     // Turn this collider into a trigger on startup
     collider.isTrigger = 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

Answer by Shkarface-Noori · May 18, 2014 at 09:23 AM

first. do you have your collider triggered? second where did you put this script? and you're just checking when a trigger is entered, you should check it when the trigger exits too.

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

Answer by HernandoNJ · Oct 07, 2021 at 02:11 AM

Check here, 2nd reply

https://answers.unity.com/questions/1474449/ontriggerenter-not-working-26.html?childToView=1864967#answer-1864967

Maybe it can help you

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

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

Related Questions

How to Apply a script During collison? 3 Answers

OnTriggerEnter On seperate object (than the script is attached to) 1 Answer

Error when accessing variables from another script: NullReferenceException: Object Reference not set to an instance of an object.. 0 Answers

The best way to trigger game events in a list 1 Answer

How can I add the GUI texts in the "Roll-A-Ball" game in Unity 4.6 ? 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