I'm busy following this YouTube tutorial for a 2D game in Unity by inScope: https://www.youtube.com/watch?v=-gC1u7qHMY4&list=PLX-uZVK_0K_6VXcSajfFbXDXndb6AdBLO&index=6
I decided to not finish the attacking episode and skipped to the next episode. But things were not working out so I deleted all my new work so everything will be back to how it was before.
But low-and-behold my attack stopped working. What should happen is whenever I press Left Shift my character should play his attack animation.
I've rechecked the videos again and again but I can't find whats wrong with my script! The script is in C#, and there are no errors in the script. I don't know whats wrong PLEASE HELP!
public class Player : MonoBehaviour
{
private Rigidbody2D myRigidbody;
private Animator myAnimator;
[SerializeField]
private float movementSpeed;
private bool attack;
private bool facingRight;
// Use this for initialization
void Start ()
{
facingRight = true;
myRigidbody = GetComponent<Rigidbody2D> ();
myAnimator = GetComponent<Animator> ();
}
void Update()
{
HandleInput ();
}
// Update is called once per frame
void FixedUpdate ()
{
float horizontal = Input.GetAxis ("Horizontal");
HandleMovement (horizontal);
Flip (horizontal);
HandleAttack ();
ResetValues ();
}
private void HandleMovement(float horizontal)
{
myRigidbody.velocity = new Vector2 (horizontal * movementSpeed, myRigidbody.velocity.y); // vector2 = x-axis - 1, y-axis = 0
myAnimator.SetFloat ("speed", Mathf.Abs (horizontal));
}
private void HandleAttack()
{
if (attack)
{
myAnimator.SetTrigger ("Attack");
}
}
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;
}
}
private void ResetValues()
{
attack = false;
}
}
GameObject
? \$\endgroup\$