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 NefonixGames · May 04, 2013 at 03:26 PM · javascriptcollisionguicollider

Problems with OnTriggerEnter

Ok so anyway I am trying to create a script where when the player enters an area a gui pops up and he takes damage like a radiation zone to stop him from going out of the map. Heres my script don't really know what's wrong with it. and by the way the character is a cube and the area i am entering is also a cube just without the mesh render with is trigger selected under box collider!

 var showgui : boolean = false;
 public var myskin : GUISkin;
 function OnCollisionEnter (col : Collision) {
 if(col.gameObject.Tag == "Player"){
 PlayerStats.curHp -= 100;
 showgui = true;
 }
 }
 function OnGUI ()
 {
     GUI.skin = myskin;
     if (showgui)
     {
         GUILayout.Box("WARNING ENTERING RADIATION ZONE");
     }
 }
 
Comment
Add comment · Show 4
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 ExTheSea · May 04, 2013 at 03:31 PM 0
Share

Did you try Debug logging? Like adding Debug.Log(col.gameobject.tag) before the if in OnCollistionEnter?

avatar image NefonixGames · May 04, 2013 at 03:42 PM 0
Share

Nope that didn't work either:(

avatar image ExTheSea · May 04, 2013 at 04:04 PM 0
Share

So the debug log wasn't called? Is the gameobject this is attached to not moving? ...because in this case OnCollisionEnter won't get called as the object isn't actually "entering" a collider. One solution you have is to let the player handle the collision with something like this

 function OnCollisionEnter (col : Collision){
   col.gameobject.Send$$anonymous$$essage("Collide", Send$$anonymous$$essageOption.DontRequiereReceiver);
 }

This will call the function Collide on every gameoject it collides with. If you can specify it to several tags you can add an if before the sendmessage cal to propably avoid performance problems.

avatar image NefonixGames · May 04, 2013 at 05:26 PM 0
Share

Not really sure how I would do this and my space ship is moving it is a cube with a click to move script and a main camera that follows it. so yeah if you could explain more sorry kind of a noob here/ more like give me the script if you can.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · May 04, 2013 at 05:46 PM

Make sure your player cube has a RigidBody on it. Make sure the above script is on the cube being entered, not on the cube that is moving. Put the following after 'showgui = true;':

Debug.Log ('radiation zone entered');

and see if it ever shows in the console. Also read the manual about using the Mono debugger. It's really important to learn to use that.

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

14 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

Related Questions

Game Over GUI Question 2 Answers

Collider is only working on the first frame 0 Answers

Collision with renderer.enabled? 0 Answers

Find colliders after collision? 2 Answers

GUI Textures and Colliders 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