Question by
NiteshRathi05 · Mar 24, 2018 at 02:06 PM ·
animationanimator controllerthird person controllerblend tree
I has a problem when i pressed "M" key animation not play. I mean amination play but not properly. Animation play properly when i hold "M" key? please help me. I want to play animation on single just click.
My Trans: Melee>>>>IDLE - 0 IDLE>>>>>Melee - 1
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Controls : MonoBehaviour {
float speed=5f;
private Animator anim;
Rigidbody rb;
bool facingRight;
void Start () {
rb = this.GetComponent<Rigidbody> ();
anim = this.GetComponent<Animator> ();
facingRight = true;
}
void Update()
{
Melee ();
}
void FixedUpdate () {
float dirX = Input.GetAxis ("Horizontal");
anim.SetFloat ("IDLE", Mathf.Abs (dirX));
//Debug.Log (Mathf.Abs (dirX));
rb.velocity = new Vector3 (speed * -dirX,rb.velocity.y,0);
if (dirX > 0 && !facingRight) flip ();
else if (dirX < 0 && facingRight) flip ();
}
void flip() {
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.z *= -1;
transform.localScale = theScale;
}
void Melee() {
if (Input.GetKeyDown (KeyCode.L)) {
anim.SetInteger ("MELEE", 0);
}
if (Input.GetKeyUp (KeyCode.L)) {
anim.SetInteger ("MELEE", 1);
}
}
}
Comment