Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class Chase : MonoBehaviour {
- public Transform player;
- static Animator anim;
- void Start ()
- {
- anim = GetComponent<Animator>();
- }
- void Update ()
- {
- if(Vector3.Distance(player.position, this.transform.position) < 1000)
- {
- Vector3 direction = player.position - this.transform.position;
- direction.y = 0;
- this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
- Quaternion.LookRotation(direction), 0.1f);
- anim.SetBool("isIdle", false);
- if(direction.magnitude > 2.75)
- {
- this.transform.Translate(0, 0, 0.05f);
- anim.SetBool("isWalking", true);
- anim.SetBool("isAttacking", false);
- }
- else
- {
- anim.SetBool("isAttacking", true);
- anim.SetBool("isWalking", false);
- }
- }
- else
- {
- anim.SetBool("isIdle", true);
- anim.SetBool("isWalking", false);
- anim.SetBool("isAttacking", false);
- }
- }
- }
Add Comment
Please, Sign In to add comment