Exemplo n.º 1
0
    void Update()
    {
        // GET HEALTH OR ANY STATUS FROM SCENE MANAGER DATA ARRAY
        if (!dataSynch)
        {
            health = sceneManagerScript.Update_GameObject_Health_OnShow(this.gameObject); dataSynch = true;
        }



        if (inp.tapObject == this.transform)
        {
            // Retrieve information from Raycast Function in inputs
            damageDelayList.Add(inp.tapObjectDamageDelay);
            damageList.Add(inp.hitDamage);
            hitPositionList.Add(inp.tapObjectPosition);

            inp.tapObject = null;
        }
        else
        {
            if (inp.tapObject == turret) // Missile Turret has a collider too
            {
                // Retrieve information from Raycast Function in inputs
                damageDelayList.Add(inp.tapObjectDamageDelay);
                damageList.Add(inp.hitDamage);
                hitPositionList.Add(inp.tapObjectPosition);

                inp.tapObject = null;
            }
        }



        // DO WE HAVE DAMAGE WAITING TO ARRIVE?

        for (i = damageDelayList.Count - 1; i >= 0; i--) // Recurse backwards in this case
        {
            if (Time.time > damageDelayList[i])
            {
                Calculate_Damage(damageList[i]);

                if (health < 0)
                {
                    bigExplosionPosition   = hitPositionList[i];
                    bigExplosionPosition.y = bigExplosionPosition.y + 2.0f; // Y Offset to reduce clipping effect on Floor
                }

                damageDelayList.Remove(damageDelayList[i]);
                damageList.Remove(damageList[i]);
                hitPositionList.Remove(hitPositionList[i]);
            }
        }



        if (health > 0)
        {
            // DISTANCE TO PLAYER

            dist = Vector3.Distance(transform.position, target.position);
        }


        // BEHAVIOUR STATES;

        switch (state)
        {
        case mode.passive:

            Do_Passive_Mode();

            break;

        case mode.alert:

            if (Time.time > reactionTimer)
            {
                state = mode.attack;
            }
            else
            {
                Do_Alert_Mode();
            }

            break;

        case mode.attack:

            Do_Attack_Mode();

            break;

        case mode.destroyed:

            Do_Destroy_Mode();

            break;
        }
    }
Exemplo n.º 2
0
    //-------------------
    // UPDATE
    //-------------------


    void Update()
    {
        // GET HEALTH OR ANY STATUS FROM SCENE MANAGER DATA ARRAY

        if (!dataSynch)
        {
            health = sceneManagerScript.Update_GameObject_Health_OnShow(this.gameObject); dataSynch = true;
        }



        if (inp.tapObject == this.transform)
        {
            // Retrieve information from Raycast Function in inputs
            damageDelayList.Add(inp.tapObjectDamageDelay);
            damageList.Add(inp.hitDamage);
            hitPositionList.Add(inp.tapObjectPosition);

            inp.tapObject = null;
        }



        if (state != mode.dying && state != mode.destroyed)
        {
            // DO WE HAVE DAMAGE WAITING TO ARRIVE?

            if (health < 0)
            {
                if (health < 0)
                {
                    state     = mode.dying;
                    temp      = 0;                 // use this for the dying Case Select
                    turnRate  = 0;
                    endTime   = 0.1f;              // This is for the flicker upon death - before deletion
                    startTime = 0.2f;              //
                    animTime  = Time.time + 0.15f; // Display first die frame for this time period
                    if (sfxShoot)
                    {
                        Stop_Looping_SFX(); sfxShoot = false;
                    }                                                       // Reset sound switch}
                    //bigExplosionPosition = hitPositionList[i];
                    //bigExplosionPosition.y = bigExplosionPosition.y + 2.0f; // Y Offset to reduce clipping effect on Floor
                }
            }

            else
            {
                for (i = damageDelayList.Count - 1; i >= 0; i--) // Recurse backwards in this case
                {
                    if (Time.time > damageDelayList[i])
                    {
                        Calculate_Damage(damageList[i]);

                        if (health < 0)
                        {
                            state     = mode.dying;
                            temp      = 0;                 // use this for the dying Case Select
                            turnRate  = 0;
                            endTime   = 0.1f;              // This is for the flicker upon death - before deletion
                            startTime = 0.2f;              //
                            animTime  = Time.time + 0.15f; // Display first die frame for this time period
                            if (sfxShoot)
                            {
                                Stop_Looping_SFX(); sfxShoot = false;
                            }                                                       // Reset sound switch}
                            //bigExplosionPosition = hitPositionList[i];
                            //bigExplosionPosition.y = bigExplosionPosition.y + 2.0f; // Y Offset to reduce clipping effect on Floor
                        }

                        damageDelayList.Remove(damageDelayList[i]);
                        damageList.Remove(damageList[i]);
                        hitPositionList.Remove(hitPositionList[i]);
                    }
                }
            }

            if (state != mode.dying)
            {
                //--------------
                if (Time.time > distanceTime)
                {
                    targetDistance = Vector3.Distance(transform.position, target.position);

                    distanceTime = Time.time + distanceStep;
                }
                //--------------
                if (targetDistance < attackRadius)
                {
                    if (state != mode.attack)
                    {
                        if (sfxShoot)
                        {
                            Stop_Looping_SFX(); sfxShoot = false;
                        }                                                       // Reset sound switch }



                        if (Time.time > flightTime)
                        {
                            i = Random.Range(0, 101);

                            fightTime = Time.time + Random.Range(2f, 7f);

                            if (i < fightOrFlight)
                            {
                                state = mode.attack;
                            }
                            else
                            {
                                flightTime = Time.time + Random.Range(2f, 5f);

                                state = mode.running;
                            }
                        }
                    }
                }
                else
                {
                    if (sfxShoot)
                    {
                        Stop_Looping_SFX(); sfxShoot = false;
                    }                                                       // Reset sound switch}
                }
            }
        }

        //--------------
        switch (state)
        {
        case mode.passive: DoStanding(); break;

        case mode.attack: Do_Attack_Mode(); break;

        case mode.running: DoRun(); break;

        case mode.dying: DoDying(); break;

        case mode.destroyed: Do_Destroy_Mode(); break;
        }
    }