Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class Zombie : MonoBehaviour
- {
- static Animator anim;
- private Transform player;
- private Rigidbody zombie;
- public float speed = 1f;
- void Start()
- {
- player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
- anim = GetComponent<Animator>();
- zombie = GetComponent<Rigidbody>();
- gameObject.GetComponent<Animator>().SetBool("isIdle", true);
- }
- void OnTriggerStay(Collider col)
- {
- if (col.tag == "Player")
- {
- Vector3 direction = player.position - this.transform.position;
- direction.y = 0;
- this.transform.rotation =
- Quaternion.Slerp(this.transform.rotation,
- Quaternion.LookRotation(direction), 0.1f);
- Vector3 velocity = direction * speed;
- anim.SetBool("isIdle", false);
- if (direction.magnitude > 0.4)
- {
- zombie.velocity = Vector3.right * Time.deltaTime;
- // this.transform.Translate(0, 0, 0.0075f); однако с Translate работает,но AI проходит сквозь стены,игнорируются физические свойства обьекта
- anim.SetBool("isWalking", true);
- anim.SetBool("isAttacking", false);
- }
- else
- {
- anim.SetBool("isAttacking", true);
- anim.SetBool("isWalking", false);
- }
- }
- }
- void OnTriggerExit(Collider col)
- {
- if (col.tag == "Player")
- {
- anim.SetBool("isWalking", false);
- anim.SetBool("isIdle", true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement