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 /
avatar image
0
Question by fdDavid18 · Aug 05, 2018 at 11:38 PM · animatortriggers

Trigger not playing animation

Hello everyone,

I'm currently experiencing a problem where the animation won't play on trigger.

I am creating a platform where the first red trigger switch would enable and disable the first platform animation to move up and down. The second red switch has the same functionality just the animation moves left to right.

alt text

I created a platform script on the Platform_1 and 2 under PlatformParents. I exposed 3 fields, the animator, the platform as a reference, and switch because it needs to trigger.

Here's my code, I am missing anim.Play(); but I don't know what to call since its only one script:

 public class PlatformScript1 : MonoBehaviour
 {
     [SerializeField] Animator anim;
     [SerializeField] GameObject Platform;
     [SerializeField] GameObject Switch;
 
     // Use this for initialization
     void Start()
     {
         anim = GetComponent<Animator>();
     }
 
     void OnTriggerEnter2D(Collider2D collision)
     {
         if (gameObject.tag == "Player")
         {
             Debug.Log("Played");
 
             //anim.enabled = true;
             anim.SetBool("Play", true);
             anim.Play("platform_1");
             anim.Play("platform_2");  //Needs to wait for 5 seconds, use coroutine?
         }
         else
             anim.SetBool("Play", false);       
     }
 }


My Switch script is under the SwitchTrigger parent also has exposed fields for animation and platform for it to link:

 public class SwitchScript : MonoBehaviour {
 
     [SerializeField] Animator anim;
     [SerializeField] GameObject platform;
 
     void OnTriggerEnter2D(Collider2D collision)
     {
         if(collision.tag == "Player" )
         {
         Debug.Log("touched");
         anim.SetBool("platform_1",true);
         anim.SetBool("platform_2", true); 
         }
     }
 }

The Play parameter is set in the animation state that I created alt text

Thanks for the help everybody.

platform-parent.png (238.5 kB)
platformstate.png (88.7 kB)
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 IvovdMarel · Aug 06, 2018 at 02:09 AM

Line 15,

 if (gameObject.tag == "Player")

should be

 if (collision.gameObject.tag == "Player")

You are checking if the Platform itself has the Player tag.

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 fdDavid18 · Aug 06, 2018 at 02:53 AM 0
Share

Thanks for the help, what about the anim.Play();? Should I have a separate scripts to play both animations ins$$anonymous$$d?

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

105 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

Related Questions

2D Animation does not start 1 Answer

How do I setup a Shooting Trigger to make an Animation play on a Platform? 0 Answers

Problem with Animation triggring 0 Answers

Insane problem with triggers 2 Answers

,Animation trigger is always set as "activated" 0 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