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 androids · Oct 01, 2013 at 01:26 AM · functionontrigger

function OnTriggerEnter doesn't work

Hi folks,

I wrote a Js for my character, but it doesn't work for me. Don't know what I did wrong. Maybe you can help me.

This is my Js;

 var character : Transform;
 var explosion : Transform;
 
 function Start()
 {
     explosion.gameObject.SetActive(false);
 }
 
 function OnTriggerEnter(other : Collider){
     if (other.gameObject.CompareTag("CharacterTag"))
     {        
         character.gameObject.SetActive(false);
         explosion.position = character.position;
         explosion.rotation = character.rotation;
         explosion.gameObject.SetActive(true);
     }
 }

I put this Js in an object and I tagged my character to "CharacterTag". But when my character moves to that object. It does nothing. It just walk trough of that object. I added a Box Collider for my character and for that object. It just didn't work.

Please someone who can help me with this problem?

Thanks in advance

Comment
Add comment · Show 6
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 Rick74 · Oct 01, 2013 at 01:39 AM 0
Share

I've only ever used if (other.gameObject.tag == "theTagYouWant")

another thing to check is that one of the two objects colliding needs a rigidbody as well as a collision box. $$anonymous$$ake sure is trigger is set on both of course.

avatar image TrickyHandz · Oct 01, 2013 at 02:52 AM 0
Share

Are you assigning the transform variables (character and explosion) through the inspector?

avatar image Rick74 · Oct 01, 2013 at 03:09 AM 0
Share

If he wasn't I think he would get a null reference error message right?

avatar image TrickyHandz · Oct 01, 2013 at 03:11 AM 0
Share

@Rick74, you are correct. There would be a null reference exception posted. I should have asked the following: Are you receiving any messages in the console?

avatar image robertbu · Oct 01, 2013 at 03:24 AM 0
Share

How are you moving your characters? Character Controllers do not cause OnTriggerEnter(). If you are using a Character Controller, you'll need to use OnControllerColliderHit() on the same object as the Character Controller.

Show more comments

2 Replies

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

Answer by androids · Oct 01, 2013 at 12:25 PM

I give an answer on my own question for those who have the same problem. What I did was just a simple step. I added a RIGIDBODY to the character. And because I don't want the character fall down, I just disabled "Use Gravity". Hope this answer would help your problem.

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
1

Answer by grayger · Oct 01, 2013 at 03:50 AM

Make sure "Is Trigger" of the collider is checked.

Comment
Add comment · Show 1 · 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 androids · Oct 01, 2013 at 10:30 AM 0
Share

"is Trigger" is checked, but it doesn't work yet

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

18 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

Related Questions

OnCollisionEnter not getting calle! 1 Answer

Coud public variables with same names cause problems? 2 Answers

Update increment error (2 + 1 = 0?) 1 Answer

Using A function in another game object 2 Answers

You are not allowed to call this function when declaring a variable. 2 Answers


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