Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by vonbetelgeuse · Jul 27, 2016 at 05:48 PM · c#collidersbooleantriggers

Check if character has entered trigger, if it has play animation on character.

I'm trying to problem solve an issue I'm having.

Basically I have a trigger zone, and when a character enters the trigger zone, I want an animation to play on the character that has just entered the trigger zone.

I vaguely understand that to make this happen I need to attach a script to the trigger zone that says

 Play("Jump1", PlayMode.StopAll);

But I don't know how to get the trigger to recognize when and which character has entered it, so the animation plays on the character inside the trigger, not the several instantiated ones outside the trigger that are tagged the same.

Is there a way I can change a boolean value only on the character that has entered the trigger?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nitin22 · Jul 27, 2016 at 06:14 PM

First tag your players on gameobject . After that just check the tag and do your rest work. Like :

 void OnTriggerEnter(Collider other) {
        if(other.tag.Equals("Player")){ 
              //Rest Work
          }
 }


Comment
Add comment · Show 5 · 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 vonbetelgeuse · Jul 27, 2016 at 07:00 PM 0
Share

Thanks for your reply Nitin22,

I tried at first doing it like this:

 void OnTriggerEnter(Collider other)
     {
 
         if (other.gameObject.tag == "triggerZone")
         {
             enemyAnimations.Play("Jump", Play$$anonymous$$ode.StopAll);
         }
     }

This script is attached to the enemy characters, from my understanding when the enemy enters the triggerZone it should make the "Jump" animation play... only it doesn't work :|

The triggerZone has a collider and is set to trigger, the enemies also have colliders, I tried giving them rigidbodies but it didn't make a difference...

avatar image Nitin22 vonbetelgeuse · Jul 27, 2016 at 07:13 PM 0
Share

Please check first tag is assigned or not . If it is then print in debug to get the result and figure out what actually going on .

avatar image vonbetelgeuse Nitin22 · Jul 27, 2016 at 07:26 PM 0
Share

Tag is definitely assigned correctly but debug does not detect any collisions of enemy with the triggerZone, it's like it's not even there.

I've checked the animations are working by adding a public boolean value to the script along the lines of:

 void OnTriggerEnter(Collider other)
     {
 
         if (other.gameObject.tag == "triggerZone")
         {
             Debug.Log(gameObject.name + " was triggered by " + other.gameObject.name);
             triggerZone = true;
         }
     }
 
     public void Update()
     {
         if (triggerZone)
         {
             enemyAnimations.Play("Jump", Play$$anonymous$$ode.StopAll);
         }
 
       
     }
 

and switching it on manually during game Play, so I know the animation works etc.

On the enemies I have two colliders, one that's a trigger for a different script (tied to a scoreboard), the other so they don't walk through each other.

I tried deleting the scoreboard script just to see if it was the cause of the problem but it didn't help, debug doesn't detect any enemy collision with the triggerZone.

Show more comments
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

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

Related Questions

How to check if player remains on a path? (2D) 1 Answer

I cant call function another script ! 1 Answer

Some questions about a jump pad (2D) 1 Answer

Animation + triggers + colliders doesn't work together 0 Answers

[SOLVED] How to Store Object Player Entered Trigger of? 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