- Home /
This question was
closed Apr 24, 2016 at 12:47 PM by
flaxor for the following reason:
fixed
Question by
flaxor · Apr 21, 2016 at 07:16 PM ·
animationscript.animator controller
cant trigger animation while jump
hi im trying make shot animation while jumping, the animation in ground is good. The problem is animation cant triggered when "player" in the air and the shot animation triggered after player touching ground.
this my controller:
and my code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
//speed move
public float Speed;
//jump var
bool grounded = false;
float groundcheckradius = 0.2f;
public LayerMask groundlayer;
public Transform groundCheck;
public float jumpheight;
Rigidbody2D myRB;
Animator myAnim;
bool facingRight;
//shooooottttt
public Transform fromwhere;
public GameObject bullet;
float firerate = 0.5f;
float nextfire = 0f;
void Start ()
{
myRB = GetComponent<Rigidbody2D>();
myAnim = GetComponent<Animator>();
facingRight = true;
}
// Update is called once per frame
void Update()
{
if(grounded && Input.GetAxis("Jump")>0)
{
grounded = false;
myAnim.SetBool("isGrounded", grounded);
myRB.AddForce(new Vector2(0,jumpheight));
}
//shot
if (Input.GetAxis("Fire1") > 0)
{
shot();
}
}
void FixedUpdate ()
{
//check if riki are grounded
grounded = Physics2D.OverlapCircle(groundCheck.position, groundcheckradius, groundlayer);
myAnim.SetBool("isGrounded", grounded);
myAnim.SetFloat("verticalSpeed", myRB.velocity.y);
float move = Input.GetAxis("Horizontal");
myAnim.SetFloat("speed", Mathf.Abs(move));
myRB.velocity = new Vector2(move*Speed, myRB.velocity.y);
flip(move);
}
void flip(float move)
{
if (move > 0 && !facingRight || move < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
void shot()
{
if (Time.time > nextfire)
{
nextfire = Time.time + firerate;
myAnim.SetTrigger("triggershot");
if (facingRight)
{
Instantiate(bullet, fromwhere.position, Quaternion.Euler(new Vector3(0, 0, 0)));
}
else if (!facingRight)
{
Instantiate(bullet, fromwhere.position, Quaternion.Euler(new Vector3(0, 0, 180f)));
}
{
}
}
}
}
thanks for your help ^^
2016-04-22-01-19-01.png
(35.5 kB)
Comment
Probably a problem with your transition settings. Check exit time etc.