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 thz343 · Mar 31, 2013 at 12:41 PM · animationtriggernumber

How do I trigger an animation when a certain number appears

Hi, I need a script that triggers an animation when i have collected 14 boxes from this script...

 using UnityEngine;
 using System.Collections;
 
  
 
 public class Boxes : MonoBehaviour {
 
     private int collected = 0; //Set up a variable to store how many you've collected
 
     public AudioClip collectedSound;     //This is the sound that will play after you collect one
 
     public GUIStyle mystyle;
 
     //This is the text that displayed how many you've collected in the top left corner
 
     void OnGUI(){
 
         GUI.Label(new Rect(40, 10, 500, 500),"Boxes:" + collected + "/14", mystyle);
 
     }
 
  
 
     private void OnTriggerEnter(Collider other){ //Checks to see if you've collided with another object
 
         if(other.CompareTag("collectable")){ //checks to see if this object is tagged with "collectable"
 
             audio.PlayOneShot(collectedSound); //plays the sound assigned to collectedSound
 
             collected++; //adds a count of +1 to the collected variable
          Destroy (other.gameObject);}}}

Please Help!

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
0
Best Answer

Answer by ExTheSea · Mar 31, 2013 at 12:53 PM

 public class Boxes : MonoBehaviour {
  
 private int collected = 0; //Set up a variable to store how many you've collected

 public Transform AnimateGO; //Drag GameObject which should be animated in here.

 public AudioClip collectedSound; //This is the sound that will play after you collect one
  
 public GUIStyle mystyle;
  
 //This is the text that displayed how many you've collected in the top left corner
  
 void OnGUI(){
  
 GUI.Label(new Rect(40, 10, 500, 500),"Boxes:" + collected + "/14", mystyle);
  
 }
  
  
  
 private void OnTriggerEnter(Collider other){ //Checks to see if you've collided with another object
  
 if(other.CompareTag("collectable")){ //checks to see if this object is tagged with "collectable"
  
 audio.PlayOneShot(collectedSound); //plays the sound assigned to collectedSound
  
 collected++; //adds a count of +1 to the collected variable
 
 if(collected == 14){
   //Play Animation here like for example:
   AnimateGO.animation.Play("AnimationName"); //Change AnimationName to the name of your animation.
 }
 
 Destroy (other.gameObject);}}}
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 thz343 · Mar 31, 2013 at 03:15 PM

@ExTheSea I tried the script on the object i wanted to animate but it didn't work. could you get it so there is a GameObject variable in the script. i tried adding it in myself but it didn't work.

Comment
Add comment · Show 3 · 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 ExTheSea · Mar 31, 2013 at 04:23 PM 0
Share

I edited my answer so that there is a Transform variable where you can drag the gameobject which should be animated in.

Btw. What you posted as an answer should have been a comment to my answer. Answers are mainly used for answers to the main question not as response to someone who posted an answer.

avatar image thz343 · Mar 31, 2013 at 05:01 PM 0
Share

Oh I didn't realise. Thanks

avatar image ExTheSea · Apr 03, 2013 at 05:44 PM 0
Share

Btw. If your question is solved please accept an answer or close the question.

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

11 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

Related Questions

Animation plays on when colliding with a trigger 1 Answer

How to trigger animations in a script using character controller ? 0 Answers

Trouble getting a trigger to activate an animation 2 Answers

Animation triggered by an animation? 1 Answer

Play 2D animations via trigger parameters 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