Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class EggPawn : MonoBehaviour
- {
- public Transform player;
- private Health myHealth;
- // Start is called before the first frame update
- void Start()
- {
- player = GameObject.FindWithTag("Player").transform;
- myHealth = GetComponent<Health>();
- }
- // Update is called once per frame
- void Update()
- {
- if (myHealth.dead) return;
- if (Vector3.Distance(transform.position, player.position) < 10)
- {
- LookAt(player);
- if (Vector3.Distance(transform.position, player.position) < 3)
- {
- GetComponent<Animator>().SetTrigger("Attack");
- }
- }
- }
- public void DamagePlayer()
- {
- if (Vector3.Distance(transform.position, player.position) < 3)
- {
- Debug.Log("Damage Player");
- }
- }
- public void LookAt(Transform target)
- {
- Vector3 targetPosition = target.position;
- targetPosition.y = transform.position.y;
- Vector3 direction = targetPosition - transform.position;
- direction.Normalize();
- transform.rotation = Quaternion.LookRotation(direction);
- }
- }
Add Comment
Please, Sign In to add comment