Exemplo n.º 1
0
 //for allies and self
 void AMolatGotHit(float damage, float percentOfHealth, GameObject attacker, GameObject victim)
 {
     //if its me
     if (victim == gameObject && _RenderedObjectsDictionary.ContainsKey(attacker))
     {
         EnemyPriority currentPriority = _RenderedObjectsDictionary[attacker];
         currentPriority.TheyHitMe(percentOfHealth);
         currentPriority.ISawYou();
         GotHit(attacker);
     }
 }
Exemplo n.º 2
0
    private void HandleRayCastVision()
    {
        RaycastHit        Hit            = new RaycastHit();
        List <GameObject> removeFromList = new List <GameObject>();

        foreach (KeyValuePair <GameObject, EnemyPriority> entry in _RenderedObjectsDictionary)
        {
            if (entry.Key == null || IsObjectDead(entry.Key))
            {
                removeFromList.Add(entry.Key);
                continue;
            }

            EnemyPriority currentPriority = entry.Value;
            Vector3       direction       = ((entry.Key.transform.position) - lookFrom.position);
            float         visionAngle     = Vector3.Angle(transform.forward, direction);
            bool          gotAHit         = false;
            if (visionAngle < maxVisionAngle)
            {
                for (float i = 0; i < 1.5f; i = i + 0.5f)
                {
                    Physics.Raycast(lookFrom.position, direction + new Vector3(0, i, 0), out Hit, 10000f);
                    if (Hit.transform && Hit.transform.gameObject == entry.Key)
                    {
                        gotAHit = true;
                        if (currentPriority.Vision == 0)
                        {
                            NewCreatureInSight(entry.Key);
                        }
                        currentPriority.setDistance(Hit.distance);
                        currentPriority.ISawYou();
                        break;
                    }
                }
            }
            if (gotAHit == false)
            {
                float lastVision = currentPriority.Vision;
                currentPriority.IDidNotSeeYou(Time.deltaTime);
                if (currentPriority.Vision == 0 && lastVision > 0)
                {
                    NewCreatureOutOfSight(entry.Key);
                }
            }
        }
        foreach (GameObject entry in removeFromList)
        {
            StopRenderingGameObject(entry);
        }
    }