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 GreenTee · Mar 19, 2015 at 08:43 AM · c#animationanimator

Play animation on death?

Hello,

i have done some tutorials to creat my first game.

To finish the project i have to add a menu that pops out when the player dies. Is it possible to play the "menu pop out"animation on collision if the animation is a "animator" animation?

I got this code:

     void OnCollisionEnter2D(Collision2D collision) {
 
         if (godMode)
         return;
 
         animator.SetTrigger("Death");

       //use other code to start animation. setTrigger will stop "death"animation
           //animator.SetTrigger("DeathMenuOpen"); 
         dead = true;
 
         }
     }
 

I tried to use the animator but if i use the "set.trigger()" code, the death animation will end.

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 Tehnique · Mar 19, 2015 at 08:49 AM 0
Share

I see 2 problems here:

  1. Why are you using an animator to open a menu?

  2. Why are you using the SA$$anonymous$$E animator to play a death animation (on your character probably) and open a menu?

Why not use another object for your menu and have that one do whatever you want on death? Different animator and all.

avatar image GreenTee · Mar 19, 2015 at 02:22 PM 0
Share

i want to open the menu with an animation and yes it is better to use an other animator for the menu but i want to start the animation when the player dies :/

avatar image Tehnique · Mar 19, 2015 at 03:02 PM 1
Share

You can do it in a lot of ways, keep a reference to the other object and call a method on it, for example. Or you could find the menu object and send it a message.

The way I'd do it is have a Level$$anonymous$$anager object that handles level started/level won/level lost/etc events. When the player dies you tell the Level$$anonymous$$anager what happened and the Level$$anonymous$$anager will handle all other things (call the menu object to open it, etc).

avatar image GreenTee · Mar 19, 2015 at 05:09 PM 0
Share

$$anonymous$$y menu has the animation "Bird$$anonymous$$enuOpen" and my player has a script to call the animation but it does not work.

Error: "The animation state Bird$$anonymous$$enuOpen could not be played because it couldn't be found! Please attach an animation clip with the name 'Bird$$anonymous$$enuOpen' or call this function only for existing animations.

my script attached on the bird to call the menu.

 using UnityEngine;
 using System.Collections;
 
 public class Bird$$anonymous$$enuOpen : $$anonymous$$onoBehaviour {
 
 
     bool birdDeath = false;
     public GameObject otherObj;
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     
     void OnCollisionEnter2D(Collision2D collision) {
         
 
         birdDeath = true;
 
         if (birdDeath == true) {
             otherObj.animation.Play ("Bird$$anonymous$$enuOpen");
             //animator.SetTrigger("Death$$anonymous$$enuOpen");
             Debug.LogError("DEATH $$anonymous$$ENU OPEN");
 
         }
         
         
     }
 }
 

2 Replies

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

Answer by GreenTee · Mar 19, 2015 at 10:56 PM

Problem solved! I had to make sure the animation is in legacy mode and the object with the animation is assigned in the inspector.

     using UnityEngine;
     using System.Collections;
     
     public class PlayerMovement : MonoBehaviour {
     
         public GameObject MenuObj;
     
     
         void OnCollisionEnter2D(Collision2D collision) {
     
                     //play animation of the menu when player collides with something!
             MenuObj.animation.Play ("BirdMenuOpen");
     
     
             }
             
         }
     


sometimes it is to easy ... :7

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
0

Answer by alok-kr-029 · Mar 19, 2015 at 09:18 AM

Create the menu open animation and put the animation on the gameobject and call the animation using animation.Play
you dont need animator

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 GreenTee · Mar 19, 2015 at 02:24 PM 0
Share

yea but the menu has to open when the player dies and i don't know how to start the animation when the player dies.

Player death > start animation of other object

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Unity 5 Broken Animations? 3 Answers

Efficient way to instantiate a sprite that plays an animation then destroys itself? (3d space) 1 Answer

UI Text Alpha not fading out in animation 0 Answers

How to make a transition animation, intermediate animation between two main states 0 Answers

issue using OverlapCircle and AnyState in Unity Animator,issue using OverlapCirlce and AnyState in Unity Animator 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