Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.AI;
- [RequireComponent(typeof(CapsuleCollider))]
- public class Unit : MonoBehaviour
- {
- private int ID;
- private int Health = 100;
- private int AttackHpt = 5;
- private int DefenceHpt = 5;
- private GameObject UnitToFollow;
- public Client client;
- private float lastTimeAttack;
- private float timeBetweenAttack;
- // Start is called before the first frame update
- void Start()
- {
- timeBetweenAttack = 5f;
- }
- // Update is called once per frame
- void Update()
- {
- float now = Time.time;
- if (UnitToFollow!=null)
- {
- GetComponent<NavMeshAgent>().SetDestination(UnitToFollow.transform.position);
- if (Vector3.Distance(transform.position, UnitToFollow.transform.position) < 40.0f)
- {
- if (now - this.lastTimeAttack > this.timeBetweenAttack)
- {
- Debug.Log("Attack");
- GetComponent<Animation>().Play("Lumbering");
- }
- }
- }
- if(Health==0)
- {
- //destroy go and send packet to destroy go
- }
- }
- public void SetUnitToFollow(GameObject unit)
- {
- UnitToFollow = unit;
- }
- public void GainDmg(int dmg)
- {
- Health -= dmg - DefenceHpt;
- }
- public void SendDmg()
- {
- //send dmg over network
- Debug.Log("Attack");
- GameObject.FindGameObjectWithTag("Client").GetComponent<Client>().SendMessage("GiveUnitDmg", new GiveUnitDmg());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement