private Animator anim; public float speed = 15f; private Vector3 target; private bool touched; void Start () { target = transform.position; anim = GetComponent<Animator> (); } void Update () { if (Input.GetMouseButtonDown(0)) { Vector3 mousePosition = Input.mousePosition; mousePosition.z = 10; // distance from the camera target = Camera.main.ScreenToWorldPoint(mousePosition); target.z = transform.position.z; var movementDirection = (target - transform.position).normalized; if (movementDirection.x != 0 || movementDirection.y != 0) { anim.SetBool("walking" , true); anim.SetFloat("SpeedX" , movementDirection.x); anim.SetFloat("SpeedY" , movementDirection.y); if (movementDirection.x < 0) { anim.SetFloat("LastMoveX" , -1f); } else if (movementDirection.x > 0) { anim.SetFloat("LastMoveX" , 1f); } else { anim.SetFloat("LastMoveX" , 0f); } if (movementDirection.y > 0) { anim.SetFloat("LastMoveY" , 1f); } else if (movementDirection.y < 0) { anim.SetFloat("LastMoveY" , -1f); } else { anim.SetFloat("LastMoveY" , 0f); } } } else { if (Mathf.Approximately(transform.position.x, target.x) && Mathf.Approximately(transform.position.y, target.y)) { touched = false; anim.SetBool("walking" , false); } else { transform.position = Vector3.MoveTowards(transform.position , target , speed * Time.deltaTime); } } What I have tried: I have tried this: however the person's code doesn't work, I tried messaging them but she/his hasn't replied in 4 weeks. Thank you.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)