Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class Enemy : MonoBehaviour {
- private Image healthBar;
- public GameObject CBTprefab;
- public int enemyAttack;
- public int enemyHealth;
- public float enemyCurrentHealth;
- Wizard wizard;
- public GameObject Wizz;
- [Header("enemy movement")]
- public Transform target;
- private int moveSpeed=5;
- private int rotationSpeed = 3;
- private Transform myTransform;
- void Awake()
- {
- healthBar = transform.FindChild("EnemyCanvas").FindChild("HealthBG").FindChild("Health").GetComponent<Image>();
- myTransform = target.transform;
- }
- void Start () {
- target = null;
- wizard = Wizz.GetComponent<Wizard>();
- enemyCurrentHealth = enemyHealth;
- }
- void Update () {
- if (target == null) return;
- else
- myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
- myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
- }
- GameObject InitCBT(string text)
- {
- Debug.Log("InitCBT called" + "text " + text);
- GameObject temp = Instantiate(CBTprefab) as GameObject;
- RectTransform tempRect = temp.GetComponent<RectTransform>();
- temp.transform.SetParent(transform.FindChild("EnemyCanvas"));
- tempRect.transform.localPosition = CBTprefab.transform.localPosition;
- tempRect.transform.localScale = CBTprefab.transform.localScale;
- temp.transform.localRotation = CBTprefab.transform.localRotation;
- temp.GetComponent<Text>().text = text;
- Destroy(temp.gameObject, 2f);
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement