Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class Enemy : MonoBehaviour {
  4.     private Image healthBar;
  5.     public GameObject CBTprefab;
  6.     public int enemyAttack;
  7.     public int enemyHealth;
  8.     public float enemyCurrentHealth;  
  9.     Wizard wizard;
  10.     public GameObject Wizz;
  11.     [Header("enemy movement")]
  12.     public Transform target;
  13.     private int moveSpeed=5;
  14.     private int rotationSpeed = 3;
  15.     private Transform myTransform;        
  16.     void Awake()
  17.     {
  18.          healthBar = transform.FindChild("EnemyCanvas").FindChild("HealthBG").FindChild("Health").GetComponent<Image>();
  19.        
  20.         myTransform = target.transform;
  21.      
  22.     }
  23.     void Start () {
  24.  
  25.         target = null;
  26.         wizard = Wizz.GetComponent<Wizard>();
  27.         enemyCurrentHealth = enemyHealth;    
  28.     }
  29.    
  30.     void Update () {
  31.    
  32.         if (target == null) return;
  33.         else
  34.         myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime);
  35.             myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
  36.      
  37.     }
  38.     GameObject InitCBT(string text)
  39.     {
  40.         Debug.Log("InitCBT called" + "text " + text);
  41.         GameObject temp = Instantiate(CBTprefab) as GameObject;
  42.         RectTransform tempRect = temp.GetComponent<RectTransform>();
  43.         temp.transform.SetParent(transform.FindChild("EnemyCanvas"));
  44.         tempRect.transform.localPosition = CBTprefab.transform.localPosition;
  45.         tempRect.transform.localScale = CBTprefab.transform.localScale;
  46.         temp.transform.localRotation = CBTprefab.transform.localRotation;
  47.         temp.GetComponent<Text>().text = text;
  48.         Destroy(temp.gameObject, 2f);
  49.         return temp;
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement