Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        int numOfRays = 15;

        fwd = transform.forward;
        fwd = Quaternion.AngleAxis(-45, Vector3.up) * fwd;
        for (int i = 0; i < numOfRays; i++)
        {
            RaycastHit hit;
            if (Physics.Raycast(transform.position, fwd * length, out hit, length))
            {
                if (hit.collider.gameObject.tag == "DeadAnimal")
                {
                    agent.stoppingDistance = 0;
                }
            }
            Debug.DrawRay(transform.position, fwd * length, Color.yellow);
            fwd = Quaternion.AngleAxis(90 / numOfRays, Vector3.up) * fwd;
        }
        targetHealth      = chaseTarget.GetComponent <Health>().CurrentHP;
        agent.destination = chaseTarget.transform.position;
        distance          = Vector3.Distance(transform.position, chaseTarget.transform.position);
        //targetHealth = hunterWander.targetHealth;
        //searching for dead animal

        // interacting with live animal

        if (chaseTarget != null)
        {
            agent.stoppingDistance = stoppingDistance;
        }

        if (targetHealth == 0)
        {
            agent.stoppingDistance = 0;
        }

        if (distance <= gunDistance)
        {
            QuinnGun Fire   = gameObject.GetComponent <QuinnGun>();
            Vector3  pos    = chaseTarget.transform.position - transform.position;
            var      newRot = Quaternion.LookRotation(pos);
            transform.rotation = Quaternion.Lerp(transform.rotation, newRot, turnSpeed);
            gun.Fire();
        }

        else if (distance > viewRange || chaseTarget == null)
        {
            hunterWander.enabled = true;
            hunterWander.target  = null;
            this.enabled         = false;
            chaseTarget          = null;
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        agent = GetComponent <NavMeshAgent>();
        GameObject Hunter = GameObject.Find("Hunter");

        hunterWander = Hunter.GetComponent <HunterWander>();
        gun          = Hunter.GetComponent <QuinnGun>();
        chaseTarget  = hunterWander.target;
        gunDistance  = gun.RayCastLength;
        viewRange    = hunterWander.length;
        fwd          = transform.TransformDirection(Vector3.forward);
        length       = stoppingDistance + 3;
    }
Ejemplo n.º 3
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Hunter")
        {
            Health    hunterHP        = other.gameObject.GetComponent <Health>();
            QuinnGun  hunterWeapon    = other.gameObject.GetComponent <QuinnGun>();
            HunterInv hunterInventory = other.gameObject.GetComponent <HunterInv>();
            //is the cooldown time good?
            if (TimeAdded + Cooldown - Time.time < 0)
            {
                TimeAdded = Time.time;
                //drop off meat
                if (hunterInventory.rabbitMeat > 0)
                {
                    Meat += hunterInventory.rabbitMeat;
                    hunterInventory.rabbitDropOff();
                    OnMeatDrop.Invoke();
                }
                //heal hunter
                if (hunterHP.CurrentHP != hunterHP.MaxHP)
                {
                    hunterHP.IncrementHP(HealAmount);
                    OnHeal.Invoke();
                }

                //add ammo to hunter's inventory
                if (hunterWeapon.AmmoReserve < hunterWeapon.MaxAmmoReserve)
                {
                    hunterWeapon.AmmoReserve += AmmoAmount;
                    if (hunterWeapon.AmmoReserve >= hunterWeapon.MaxAmmoReserve)
                    {
                        hunterWeapon.AmmoReserve = hunterWeapon.MaxAmmoReserve;
                    }
                    OnAmmoRefill.Invoke();
                }
                //is the hunter's mag empty? if so call reload (this is for if the hunter enters the camp with no ammo so the gun will reload if it's empty)
                if (hunterWeapon.InMag <= 0)
                {
                    hunterWeapon.ReloadStart();
                }
            }
            //if hunter at max hp and ammo in reserve and has no meat in their inventory then have the hunter wander again
            if (hunterHP.CurrentHP == hunterHP.MaxHP && hunterWeapon.AmmoReserve == hunterWeapon.MaxAmmoReserve && hunterInventory.rabbitMeat == 0)
            {
                other.gameObject.GetComponent <NavMeshAgent>().speed   = other.gameObject.GetComponent <HunterReturn>().hunterSpeed;
                other.gameObject.GetComponent <HunterWander>().enabled = true;
            }
        }
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        agent = GetComponent <NavMeshAgent>();
        // GameObject homeBase = GameObject.Find("HunterCamp");
        GameObject Hunter = GameObject.Find("Hunter");

        agent.speed   = hunterSpeed;
        speed         = hunterSpeed;
        health        = Hunter.GetComponent <Health>();
        ammo          = Hunter.GetComponent <QuinnGun>();
        meat          = Hunter.GetComponent <HunterInv>();
        maxHealth     = health.MaxHP;
        currentHealth = health.CurrentHP;
        ammoMax       = ammo.MaxAmmoReserve;
        totalMeat     = meat.rabbitMeat;
        chase         = GetComponent <HunterChase>();
        wander        = GetComponent <HunterWander>();
    }
 // Use this for initialization
 void Start()
 {
     gun        = GameObject.FindGameObjectWithTag("Hunter").GetComponent <QuinnGun>();
     output     = GetComponent <Text>();
     initalText = output.text;
 }