void Start()
{
rigidbody = GetComponent<Rigidbody2D>();
currentState = "Idle";
SetCharacterState(currentState);
}
private void FixedUpdate()
{
if (Physics2D.Linecast(transform.position, GroundCheck.position, 1 << LayerMask.NameToLayer("Ground")))
{
isGrounded = true;
}
else
{
isGrounded = false;
SetAnimation(jumping, false, 1f);
}
}
// Update is called once per frame
void Update()
{
Move();
if (isGrounded == true )
{
canJump = true;
}
else
{
canJump = false;
}
if (canWallJump == true)
{
canJump = true;
SetCharacterState("WallJUMP");
}
Dash();
}
public void SetAnimation(AnimationReferenceAsset animation, bool loop, float timeScale)
{
if (animation.name.Equals(currentAnimation))
{
return;
}
Spine.TrackEntry animationEntry = skeletonAnimation.state.SetAnimation(0, animation, loop);
animationEntry.TimeScale = timeScale;
animationEntry.Complete += animationEntry_Complete;
currentAnimation = animation.name;
}
private void animationEntry_Complete(Spine.TrackEntry trackEntry)
{
if (currentState.Equals("Jumping"))
{
SetCharacterState(previousState);
}
}
public void SetCharacterState(string state)
{
if (state.Equals("Run"))
{
SetAnimation(run, true, 2f);
}
else if (state.Equals("Jumping"))
{
SetAnimation(jumping, false, 2f);
}
else
{
SetAnimation(idle, true, 1f);
}
if (state.Equals("DASH"))
{
SetAnimation(DASH, true, 1f);
}
if (state.Equals("WallJUMP"))
{
{
SetAnimation(WallJUMP, false, 1f);
return;
}
}
currentState = state;
}
public void Move()
{
movement = Input.GetAxis("Horizontal");
rigidbody.velocity = new Vector2(movement * speed, rigidbody.velocity.y);
if (movement != 0)
{
if (!currentState.Equals("Jumping"))
{
SetCharacterState("Run");
}
if (movement > 0)
{
transform.localScale = new Vector2(0.1f, 0.1f);
}
else
{
transform.localScale = new Vector2(-0.1f, 0.1f);
}
}
else
{
if (!currentState.Equals("Jumping"))
{
SetCharacterState("Idle");
}
}
if (Input.GetButtonDown("Jump") && canJump)
{
Jump();
}
}
public void Jump()
{
rigidbody.velocity = new Vector2(rigidbody.velocity.x, jumpSpeed);
if (!currentState.Equals("Jumping"))
{
previousState = currentState;
}
SetCharacterState("Jumping");
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
canWallJump = true;
}
}
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.tag.Equals("Wall"))
{
canWallJump = false;
}
}
void Dash()
{
if (Input.GetKeyDown(KeyCode.LeftControl) && !lockDash)
{
lockDash = true;
Invoke("DashLock", 1f);
SetCharacterState("DASH");
rigidbody.velocity = new Vector2(0, 0);
if (!currentState.Equals("Dash"))
{
previousState = currentState;
}
if (rigidbody.transform.localScale.x < 0)
{
rigidbody.AddForce(Vector2.left * DashInpulse);
}
else
{
rigidbody.AddForce(Vector2.right * DashInpulse);
}
}
}
private bool lockDash = false;
void DashLock()
{
lockDash = false;
}
}
WallJUMP and DASH animations only play the first frame.You can see where there are errors in the code for these two animations and what I need to fix.I can't figure it out by myself!please take a couple of minutes of your time and look at the code.