Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TestAi : MonoBehaviour
- {
- float speed = 3f;
- public Transform Player;
- float maxHealth = 10f;
- float health;
- public Collider body;
- float playerDamage;
- void Start()
- {
- health = maxHealth;
- playerDamage = KnightCntrl.damage;
- }
- // Update is called once per frame
- void Update()
- {
- MoveTowardsPlayer();
- if(health <= 0)
- {
- Destroy(this.gameObject);
- }
- }
- void MoveTowardsPlayer()
- {
- if (Vector3.Distance(Player.position, transform.position) < 10)
- {
- Vector3 dir = Player.position - transform.position;
- dir.y = 0;
- transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir), 0.1f);
- if (dir.magnitude < 10 && dir.magnitude > 1)
- {
- transform.Translate(0f, 0f, speed * Time.deltaTime);
- }
- }
- }
- private void OnTriggerEnter(Collider body)
- {
- if (body.CompareTag("Sword")) { health -= playerDamage; }
- Debug.Log(health);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement