daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jan 16th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.AI;
  3.  
  4. [RequireComponent(typeof(CapsuleCollider))]
  5. public class Unit : MonoBehaviour
  6. {
  7.     private int ID;
  8.     private int Health = 100;
  9.     private int AttackHpt = 5;
  10.     private int DefenceHpt = 5;
  11.     private GameObject UnitToFollow;
  12.     public Client client;
  13.  
  14.     private float lastTimeAttack;
  15.     private float timeBetweenAttack;
  16.  
  17.     // Start is called before the first frame update
  18.     void Start()
  19.     {
  20.         timeBetweenAttack = 5f;
  21.     }
  22.  
  23.     // Update is called once per frame
  24.     void Update()
  25.     {
  26.         float now = Time.time;
  27.  
  28.         if (UnitToFollow!=null)
  29.         {
  30.             GetComponent<NavMeshAgent>().SetDestination(UnitToFollow.transform.position);
  31.  
  32.             if (Vector3.Distance(transform.position, UnitToFollow.transform.position) < 40.0f)
  33.             {
  34.                 if (now - this.lastTimeAttack > this.timeBetweenAttack)
  35.                 {
  36.                     Debug.Log("Attack");
  37.                     GetComponent<Animation>().Play("Lumbering");
  38.                 }
  39.             }
  40.         }
  41.        
  42.         if(Health==0)
  43.         {
  44.             //destroy go and send packet to destroy go
  45.         }
  46.     }
  47.  
  48.     public void SetUnitToFollow(GameObject unit)
  49.     {
  50.         UnitToFollow = unit;
  51.     }
  52.  
  53.     public void GainDmg(int dmg)
  54.     {
  55.         Health -= dmg - DefenceHpt;
  56.     }
  57.  
  58.     public void SendDmg()
  59.     {
  60.         //send dmg over network
  61.         Debug.Log("Attack");
  62.         GameObject.FindGameObjectWithTag("Client").GetComponent<Client>().SendMessage("GiveUnitDmg", new GiveUnitDmg());
  63.     }
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top