- Home /
Play a animation on an action?
I have looked for a solution on google and had no luck, but it does not seem all that hard to do. All I want is for when the position of my object is equal to a position, to play an animation. Here is my script:
using UnityEngine; using System.Collections;
public class Obstacles : MonoBehaviour { public float ResetPosition; public float OffScreen; public float Max = 3f; public float Min = -4.36f; public float YMax; public float YMin; public float XMin; public float XMax; public bool PlayAnimation;
// Use this for initialization
void Start () {
PlayAnimation = false;
}
// Update is called once per frame
void Update () {
this.transform.Translate (-Vector3.right * 6 * Time.deltaTime);
Debug.Log("Moving");
if (this.transform.position.x < OffScreen) {
Vector3 NewPos = new Vector3(Random.Range(XMin,XMax), Random.Range (Min,Max));;
this.transform.position = NewPos;
PlayAnimation = true;
Debug.Log("is offScreen");
}
if (PlayAnimation == true) {
//play animation here
}
}
}
Answer by sas_88 · May 13, 2015 at 08:22 AM
Update is called every frame when playAnimation set true the animation starts play.
In ur script u have not reset playAnimation after it became true,so animation starts playing every frame . so change the script as
if (PlayAnimation == true)
{
//play animation here
PlayAnimation=false;
}
Thank You, but that is not my problem. $$anonymous$$y problem is that I want to play a specific animation at that time, like a c# of animation.Play("ExplodeAnimation").
Try this you will get relevant solution,
Assets....>Import package....>Character
Import characters in Standard Asset folder and go through ThirdPersonController script.
If character doesnot exist in Import pacakage,download installer from the link and install
Your answer
Follow this Question
Related Questions
Animation not be found 1 Answer
Running animation 1 Answer
How to go to starting point of an animation which is running already? 1 Answer
Attack Animation problem 1 Answer
On Hit play animation 0 Answers