Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Ep8s · Aug 23, 2021 at 05:20 AM · animationevent triggeringrhythm

How would I make an animation play when a certain gameObject is destroyed?

im trying to make an fnf remake, but i am stuck at the enemy animations and all i have is the arrows disappear when colliding with the enemy's buttons. here is the script i attached to the buttons for the arrows to be destroyed:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Destroy : MonoBehaviour
 {
     void OnCollisionEnter2D(Collision2D col)
     {
     if(col.gameObject.name == "GameButton")
     {
     Destroy(col.gameObject);
     }
     }
 }


but how would i go about playing one of 4 animations when this happens. keep in mind this is a seperate game object to the enemy arrows and buttons, how would i trigger an animation when these gameobjects are destroyed? Would i need to make a different script for the enemy player singing animations or would i attach this script to them? thank you, Ep8s.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Honorsoft · Aug 23, 2021 at 08:49 AM

First of all, don't be so quick to just destroy the object. Sometimes when you destroy an object it causes a problem with another object that was "interacting" with it, or you may want the object to finish playing a complete sound before it disappears. One way to do that is using a boolean to keep track whether it is time to destroy an object, like bool DestroyMe = "true"

Or, you could use a "controller" object (something that I like to do), which is an object that handles all the creating, destroying, sound-playing, and all the other stuff like that. To do that, you make a script on your "game controller" object, and in the Awake function, you put DontDestroyOnLoad(this.gameObject); So, now that object won't be destroyed automatically when you change game-scenes, so it can play background music without stopping while loading different scenes, or trigger animations to play on different objects, keep track of the amount of enemies left in the scene, or destroy an enemy, etc.


Brackey's explains that in this tutorial at 1 minutes 50 seconds into the video: https://www.youtube.com/watch?v=hkaysu1Z-N8

So you'll need to use Unity's Animator Controller and a script that accesses that controller. ...The video should explain it but here's a basic example with some stuff you might need:

 using UnityEngine;
     
     public class AnimatorGetBool : MonoBehaviour
     {
     
         Animator m_Animator; // make a "holder" for an Animator called m_Animator
         public GameObject animObject; //set the object in the Inspector that you want to control or interact with
         int whichChoice = 0; //a variable for choosing a random choice
     
         void Start()
         {
             m_Animator = animObject.GetComponent<Animator>(); //get the Animator during run-time (caching)
     
         }
     
         void OnTriggerEnter (Collider other) //called automatically when collision occurs
         {
         //if the colliding object is tagged Enemy...
             if (other.gameObject.tag == "Enemy")
         {
             m_Animator.SetBool ("Explode1Play", true);} //Play an explosion sound or animation
     
         whichChoice = Random.Range(0, 4); //choose a random number between 0 and 3 (4 numbers)
         
         if (whichChoice == 0)
         {
             //do the 1st thing
         }
     
         if (whichChoice == 1)
         {
             //do the 2nd thing
         }
     
         if (whichChoice == 2)
         {
             //do the 3rd thing
     
         if (whichChoice == 3)
         {
             //do the 4th thing
     
         }
         }
     
         }
     
         void Update()
         {
           
         }
     
     }//END
 

*Note that an animation controller can do a lot more than just play animations. Using the Animator variables, "Animator Events" and scripts, you can trigger sounds to play at specific times during animations and much more.

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 Ep8s · Aug 23, 2021 at 11:03 PM

i mean you know how in friday night funkin, the character opposing the player sings via ai? i already have the script that destroys the arrows on the opponent's side but i need to figure out how to get the npc opponent to have up, down, left and right singing animations when for example, the ai opponent hits an up arrow, they sing up. like that.

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

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

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

Can I make animations snap to a frame? 1 Answer

Adding animation to UI buttons? 0 Answers

How to select an animation clip by index number? 7 Answers

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 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