This code worked before I added the slide feature.
THE ERROR I'M GETTING IS AS FOLLOWS EVEN THOUGH IT WORKED BEFORE AND I AM TOO OBLIVIOS TO SEE WHAT I DID WRONG.
Assets/Script/PlayerWalk.cs(50,28): error CS1061: Type PlayerWalk' does not contain a definition for
GetCurrentAnimatorStateInfo' and no extension method GetCurrentAnimatorStateInfo' of type
PlayerWalk' could be found. Are you missing an assembly reference?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerWalk: MonoBehaviour { private Rigidbody2D myRigidbody;
private Animator myAnimator;
[SerializeField]
private float movementSpeed;
private bool attack;
private bool slide;
private bool facingRight;
void Awake()
{
facingRight = true;
myRigidbody = GetComponent < Rigidbody2D > ();
myAnimator = GetComponent < Animator > ();
}
void Update()
{
HandleInput();
}
void FixedUpdate()
{
float horizontal = Input.GetAxis("Horizontal");
HandleMovement(horizontal);
Flip(horizontal);
HandleAttacks();
ResetValues();
}
private void HandleMovement(float horizontal) {
if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack")) {
myRigidbody.velocity = new Vector2(horizontal * movementSpeed, myRigidbody.velocity.y);
}
//WHEN TO SLIDE
if (slide && !this.GetCurrentAnimatorStateInfo(0).IsName("Slide"))
{
myAnimator.SetBool("slide", true);
}
else if (!this.myAnimator.GetCurrentAnimatorStateInfo(0).IsName("slide"))
{
myAnimator.SetBool("slide", false);
}
myAnimator.SetFloat("speed", Mathf.Abs(horizontal));
}
//ATTACK CODE
private void HandleAttacks() {
if (attack && !this.myAnimator.GetCurrentAnimatorStateInfo(0).IsTag("Attack"))
{
myAnimator.SetTrigger("attack");
myRigidbody.velocity = Vector2.zero;
}
}
//DETECTING PLAYER INPUT
private void HandleInput() {
if (Input.GetKeyDown(KeyCode.LeftShift))
{
attack = true;
}
}
private void Flip(float horizontal) {
if (horizontal > 0 && !facingRight || horizontal < 0 && facingRight)
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
//RESET WHEN FINISHED
private void ResetValues()
{
attack = false;
slide = false;
}
} // class
Your answer
Follow this Question
Related Questions
How to have UI Manager come up on collision? 0 Answers
How To Do Basic 2D Movement? 1 Answer
Parsing error? 1 Answer
Player can only jump once!? 0 Answers
Sprites appears corrupted in standalone build, but not editor. 0 Answers