public void SetScarePoints(GameObject T, float sightRadius, Stats stats)
    {
        Stats  ownStats  = stats;
        Points ownPoints = T.GetComponent <Unit>().publicPoints;

        otherUnits = 0;
        foreach (RaycastHit r in T.transform.getWithinSphere(sightRadius))
        {
            IAmLiving livingUnit = r.collider.GetComponent <IAmLiving>();         //check for component idamagable on the hit object
            if (livingUnit != null && livingUnit != T.GetComponent <IAmLiving>()) //"if object has IAmLiving"
            {
                otherUnits++;
                scaredMod = 0;
                Stats othersStats = r.collider.GetComponent <Unit>().publicStats;

                scaredMod += Mathf.Clamp(25 / Extensions.distanceInPow(T.transform, r.transform.position), 0, 25);
                scaredMod += (ownStats.health - othersStats.health) * -2;
                scaredMod += (ownStats.sizeMod - othersStats.sizeMod) * -10;
                scaredMod += (ownStats.strenght - othersStats.strenght) * -10;
                scaredMod += (ownStats.stamina - ownStats.maxStamina) * 0.2f;
                scaredMod += ownStats.hunger;
            }
        }
        if (otherUnits == 0 && scaredMod > 0)
        {
            scaredMod--;
        }
        ownPoints.scaredPoints = scaredMod;
    }
Exemplo n.º 2
0
 //this will run every 0.1 seconds
 override protected void Behaviour()
 {
     base.Behaviour();
     if (!hasTarget)
     {
         Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius, trees);
         if (hitColliders.Length > 0)
         {
             target    = hitColliders[0].gameObject;
             tree      = target.GetComponent <IAmLiving>();
             hasTarget = true;
         }
         else
         {
             radius   += 1;
             hasTarget = false;
         }
     }
     else
     {
         if (target != null)
         {
             stats.getAnimalStats.getHungry = -0.1f;
             if (Vector3.Distance(transform.position, target.transform.position) <= 2f)
             {
                 agent.speed = 0;
                 stats.getAnimalStats.getHungry = 0.5f;
                 tree.TakeDamage(0.1f);
             }
             else
             {
                 agent.speed = 5;
                 agent.SetDestination(target.transform.position);
             }
         }
         else
         {
             hasTarget = false;
             radius    = 10;
         }
     }
     //print("script"+scriptNR);
 }