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 Steve L · Jun 15, 2015 at 09:46 AM · animationtriggerplayerpolygon collider 2d

How to start an animation of the object itself by trigger enter in #C?

Hey folks, I am making a game where the main character can encounter bushes and branches. I intended to start an animation of these branches that makes them wave during an encounter with the player. I now have 2 scripts. one attached to the branch and one on the polygon collider which is on the branch. I am asking this question because I wasn't able to find this problem in #C

The branch scripts looks like this:

 using UnityEngine;
 using System.Collections;
 public class MovingBranch: MonoBehaviour {
     
     public bool PlayAnimation = false;
     
     
     void Start () {    
         
     }
     
     
     void Update () {
         if(PlayAnimation){
             // Whatever function or code you write to start the animation
             // or however you want to do the animation}
         }
     }
 }
 

And the script attached on the polygon collider looks like this:

 using UnityEngine;
 using System.Collections;
 
 public class Box: MonoBehaviour {
     // Make sure you have the Branch Object
     public GameObject Branch;
     // The Script of the Branch;
     private MovingBranch movingbranch;
     
     
     void Start () {    
         // This will get the script and set the trainscript
         movingbranch= Branch.GetComponent("MovingBranch") as MovingBranch ;
     }
     
     // Update is called once per frame
     void Update () {
         
     }
     
     void OnTriggerEnter(Collider collision){
         if(collision.gameObject.tag == "Player"){
             movingbranch.PlayAnimation = true;
         }
     }
 }

I converted a existing script into my project but it simply doesn't work even though there are no errors. I don't know why the animation is not started when being touched by the main player? I am a beginner in scripting.

If somebody can point me into the right direction that would be really helpful :)

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 DreamEnder · Jun 15, 2015 at 10:32 AM

Put some Debug.Log messages in your methods and check if the player is colliding with the branch.

For now you could just replace:

 if(collision.gameObject.tag == "Player"){
        movingbranch.PlayAnimation = true;
 }

With:

 movingbranch.animation.Play();

To see if it works.

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 Steve L · Jun 15, 2015 at 12:08 PM 0
Share

thanks for your quick reply, unfurtunately i got this; alt text

alt text

screen-shot-2015-06-15-at-20508-pm.png (22.1 kB)
screen-shot-2015-06-15-at-20725-pm.png (14.0 kB)
avatar image DreamEnder · Jun 15, 2015 at 12:12 PM 0
Share

Ok try this:

 movingbranch.GetComponent<Animation>().Play();

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Getting My FPS Controller To Play An Animation After A Trigger Event 1 Answer

Trail of color behind the player 2D c# 1 Answer

Idle Animations, Player Walking 0 Answers

Mechanim trigger problem 1 Answer

Initiate Animation 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