Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using System.Collections;
- public class Сhase : MonoBehaviour
- {
- public Transform player;
- Animator Anim;
- public int i;
- public float time;
- // Use this for initialization
- void Start ()
- {
- Anim = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update ()
- {
- Vector3 direction = player.position - this.transform.position;
- float angle = Vector3.Angle(direction, this.transform.forward);
- if (Vector3.Distance(player.position, this.transform.position) < 20 && angle < 90)
- {
- direction.y = 0;
- this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f*Time.deltaTime);
- Anim.SetBool("isIdle", false);
- if (direction.magnitude > 1.5f)
- {
- this.transform.Translate(0, 0, 0.035f);
- Anim.SetBool("isRunning", true);
- Anim.SetBool("isAttacking", false);
- }
- else
- {
- Anim.SetBool("isRunning", false);
- Anim.SetBool("isAttacking", true);
- }
- }
- else
- {
- this.transform.Translate(0, 0, 0.005f);
- if (i == 0)
- {
- int sens = new System.Random().Next(0,2);
- if (sens == 0)
- {
- Anim.SetBool("isTurningLeft", true);
- Debug.Log(Anim.GetBool("isTurningLeft").ToString());
- this.transform.Rotate(new Vector3(0, -90, 0));
- }
- else
- {
- Anim.SetBool("isTurningRight", true);
- Debug.Log(Anim.GetBool("isTurningRight").ToString());
- this.transform.Rotate(new Vector3(0, 90, 0));
- }
- i = 5;
- time = Time.realtimeSinceStartup;
- }
- else
- {
- Anim.SetBool("isTurningRight", false);
- Anim.SetBool("isTurningLeft", false);
- }
- if (Time.realtimeSinceStartup - time > 2)
- {
- --i;
- time = Time.realtimeSinceStartup;
- }
- Debug.Log(i.ToString());
- Debug.Log("turnfalse");
- Anim.SetBool("isIdle", true);
- Anim.SetBool("isRunning", false);
- Anim.SetBool("isAttacking", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement