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);}}}
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);}}}
@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.