I’m working on coding in some animation for a project. I need a jumping animation to play once the camera moves to a certain height, then a falling animation to play after that animation and loop until I activate a grabbing animation after a touch input. The later stuff shouldn’t be that difficult but I’m having trouble with getting the first two to work together.
public class TouchScreenTests_Player_Redux : TouchScreenTests_Core {
//Inherits from the TouchScreenTests_Core script instead of MonoBehavior
//Detects whether the character is on the first jump of the level or not.
public bool levelStart;
//Detects whether the character is falling or not.
private bool falling;
//Sets up touchBegan and touchEnd values
private Vector2 touchBegin, touchEnd;
private bool touchBegan;
//Creates variables for the characters transform and the cameras transform.
private Transform myTransform, camTransform;
//Sets the characters movement speed for horizontal movement
public float speed = 15.0f;
//Sets a check for whether the jump animation has played or not.
public bool jumpHasPlayed = false;
//Sets a check for whther the grabbing animation has played or not.
public bool grabHasPlayed = false;
public GameObject anchor;
public GameObject Thief;
private Vector2 screenPos;
public bool paused;
void Start ()
{
//Sets the LevelStart value to true, only once.
levelStart = true;
//Sets the falling value to false
falling = false;
Thief = GameObject.FindGameObjectWithTag ("Thief");
//Turns off gravity at the start of the level for this rigidbody.
//this.rigidbody.useGravity = false;
//Sets myTransform to the transform to which this code is assigned.
myTransform = this.transform;
//Sets camTransform to the transform of the main camera
camTransform = Camera.main.transform;
}
void Update ()
{
TouchCheck();
if (camTransform.position.y >= 180.0f && levelStart == true)
{
Thief.animation.Play ("Jumping");
jumpHasPlayed = true;
levelStart = false;
Debug.Log ("Jump has Played");
}
if (!Thief.animation.isPlaying && camTransform.position.y <= 180.0f && levelStart == false);
{
Thief.animation.Play ("Falling");
}
The problem I’ve run into is that the “Falling” animation is overiding the Jumping animation and I can’t cause any other animation to play once it does (I’ve got a secondary code just to test things that plays animation after button input). the “Jump has Played” Debug happens but the actual jump animation does not play. Currently the Camera starts out at around 200 so the Jump animation should play first, and because an animation is playing Falling shouldn’t play until that is done. Although, the Thief.animation.isPlaying is something I guessed on the spot in hopes of it working because this code is not on the object being animated so animation.isPlaying doesn’t work, it tries to find an animation on the object this code is attached to.
I’m looking for a way to basically tier the animation priority or anything like that. Also, a way to detect whether a specific animation has ended so I can move the jumpHasPlayed and levelStart variables into a statement with that so they don’t change until the animation actually finishes. I’ve looked through PlayQueued on the Script reference but I’m not really getting it so any explanation on that may help as well…