#unity #tutorial #animator #animation #script
PNG: https://www.dropbox.com/s/n02l16tciwl...
!!!! these characters "˂" and "˃" are unicodes, you have to replace it with asciicodes !!!!
// -- C# Script --
using UnityEngine;
public class MovePlayer : MonoBehaviour
{
public float speed = 2.0f;
Rigidbody2D rb;
Animator animator;
private Vector2 direction;
// Start is called before the first frame update
void Start()
{
rb = GetComponent˂Rigidbody2D˃();
animator = GetComponent˂Animator˃();
}
// Update is called once per frame
void FixedUpdate()
{
float h = Input.GetAxisRaw("Horizontal"); // possible values -1,0,+1 (left,none,right)
float v = Input.GetAxisRaw("Vertical"); // possible values -1,0,+1 (up,none,down)
bool jump = Input.GetButton("Fire1"); // left ctrl
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("JumpRight") && !animator.GetCurrentAnimatorStateInfo(0).IsName("JumpLeft")) {
direction = new Vector2(h,v);
rb.velocity = direction.normalized * speed; // Normalized causes diagonal movements to be not faster than horizontal or vertical ones.
}
animator.SetBool("isMoveRight",(h˃0));
animator.SetBool("isMoveLeft",(h˂0));
animator.SetBool("isFirePressed",(jump));
}
}