Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Boollean problem, animation trigger

Discussion in 'Scripting' started by cristo, May 31, 2016.

  1. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Hi,

    I believe this is simple, but I can't get it to work right.

    I just want to create a bool where one animation will play only after another has finished playing completely.

    If anyone can help that would be great.


    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BoolScript : MonoBehaviour {
    5.  
    6.     public GameObject Bump;
    7.     public GameObject Dawk;
    8.     public bool AnimationPlayed = false;
    9.    
    10.     // Use this for initialization
    11.     void Start () {
    12.      
    13.  
    14.         Dawk.GetComponent<Animation>().Play("Roll");
    15.         AnimationPlayed = true;
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.  
    21.         if (AnimationPlayed = true) {
    22.             Bump.GetComponent<Animation>().Play("Jump");
    23.         }
    24.      
    25.  
    26.        
    27.     }
    28. }
     
  2. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    Maybe soemthing like

    Code (CSharp):
    1. void Update() {
    2.    if( Dawk.GetComponent<Animation>().time >= Dawk.GetComponent<Animation>().length ) {
    3.       Dawk.GetComponent<Animation>().Stop();
    4.       AnimationPlayed = true;
    5.        Bump.GetComponent<Animation>().Play("Jump");
    6.    }
    7. }
     
    cristo likes this.
  3. cristo

    cristo

    Joined:
    Dec 31, 2013
    Posts:
    265
    Thanks I'll give this a try tomorrow. Thanks for your help.