Question by
haespiritu · Jul 22, 2016 at 08:17 AM ·
animation2d gameanimatorjumping
Why isn't my jumping animation working?
I am having trouble with my jumping animation. I have it going from "idle" to "take off" to "landing". When I press the key, the animation does not work. Here is the code:
using UnityEngine; using System.Collections;
public class PlayerCode : MonoBehaviour {
// Use this for initialization
Animator a;
public Transform FirePoint;
[SerializeField]
private GameObject Projectile;
public float speed;
public bool Throw;
bool ground = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public float jumpForce = 700f;
public LayerMask isGround;
void Start () {
a = GetComponent<Animator> ();
}
void Update()
{
if (ground && Input.GetKeyDown (KeyCode.UpArrow)) {
TakeOff ();
}
if (Input.GetKeyDown (KeyCode.Space)) {
Throw = true;
if(Throw)
a.SetTrigger ("throw");
ThrowKnife (0);
//if (other.tag == "Enemy") {
//Instantiate (enemyDeathEffect, other.transform.position, other.transform.rotation);
//Destroy (other.gameObject);
//}
Throw = false;
}
}
// Update is called once per frame
void FixedUpdate () {
ground = Physics2D.OverlapCircle (groundCheck.position, groundRadius, isGround);
a.SetBool ("Ground", ground);
a.SetFloat ("VerticalSpeed", GetComponent<Rigidbody2D> ().velocity.y);
}
void ThrowKnife(int value)
{
Instantiate (Projectile, FirePoint.position, Quaternion.identity);
}
void TakeOff()
{
a.SetTrigger ("Jump");
GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, jumpForce));
Landing ();
}
void Landing()
a.ResetTrigger ("Jump");
}
}
Comment
Your answer
Follow this Question
Related Questions
Attaching Armour 2D sprites 0 Answers
How do I stop an animation from looping? 1 Answer
sync child animations with parent animations 0 Answers
Animating scripted jumping 1 Answer