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 SpeedTutor · Mar 13, 2013 at 08:27 PM · javascriptcollidertriggerwalking

Boolean detection on collision.

I'm not sure what I'm doing wrong but I have a simple script which sets boolean true or false depending on whether the collider is entered or not. I'm trying to make it bring up a debug log before I add the sound effect and counter for walking.

The collider is set to "Is Trigger", so I'm not sure if there is something else.

 #pragma strict
 
 var GrassBool : boolean = false;
 
 function OnTriggerEnter (Grass : Collider)
 {
     if(Grass.gameObject.tag=="Player")
     {
         GrassBool = true; 
     }
 }
 
 function OnTriggerExit (Grass : Collider)
 {
     if(Grass.gameObject.tag=="Player")
     {
         GrassBool = false; 
     }
 }
 
 function Update ()
 {
     if(Input.GetKey(KeyCode.W) && GrassBool == true)
     {
         Debug.LogWarning("You are on grass");
     }
 }
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 ByteSheep · Mar 13, 2013 at 08:30 PM 0
Share

Did you add this script to the player or the Grass collider? If you added it to the player then checking if the collider tag is "player" won't make any sense :) Here's a simple way to see what colliders you are hitting - add this debug:

Debug.Log("Hit object with tag: "+Grass.gameObject.tag)

just after this line:

function OnTriggerEnter (Grass : Collider) {

avatar image SpeedTutor · Mar 13, 2013 at 09:34 PM 0
Share

Thanks for your time. I already had the script on the collider, as you say wouldn't work otherwise.

I added the debug and it brought back the tag as "Untagged". I'm 100% sure my FPS controller is tagged "Player".

Unless something which is a child is untagged...

avatar image ByteSheep · Mar 13, 2013 at 09:53 PM 0
Share

Perhaps try this ins$$anonymous$$d to see what the object name is:

 Debug.Log("Hit object named: "+Grass.gameObject.name) 
avatar image SpeedTutor · Mar 13, 2013 at 10:08 PM 0
Share

I didn't realise you could debug that way. Seems like it's finding a gameObject that isn't used anymore. I disable the object and the collider doesn't pass any debug. I swear there is a different problem every time I try something like this -.-

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MileSplit · Mar 13, 2013 at 09:40 PM

Hello, This gave me quite the headache. You need to have a rigidbody attached to one of the objects.

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 SpeedTutor · Mar 13, 2013 at 09:48 PM 0
Share

I thought that myself but added it to either object and makes no difference to what happens. Still throws back "Untagged".

avatar image MileSplit · Mar 13, 2013 at 10:14 PM 0
Share

Ok it was just a thought

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

12 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

Related Questions

Collision with renderer.enabled? 0 Answers

make script target player that enters collider 0 Answers

Collider not working... 0 Answers

Trigger Enter and Exit not working properly? 2 Answers

Boolean wont acitvate if the enemy enters a trigger 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