Exemplo n.º 1
0
    void Update()
    {
        if (!IsInit)
        {
            return;
        }

        // -----------------------------------------------------------------------------------
        // Animation
        // -----------------------------------------------------------------------------------
        float wobble = Mathf.Sin(Time.realtimeSinceStartup * 4f);

        if (RootRotation != null)
        {
            if (IdleWaitTimer < 0.0f)
            {
                IdleWobble = Mathf.Min(IdleWobble + Time.deltaTime, 1f);
                if (RootRotation.Step(Time.deltaTime))
                {
                    IdleWaitTimer = 0.0f;
                }
            }
            else
            {
                IdleWobble     = Mathf.Max(IdleWobble - Time.deltaTime, 0f);
                IdleWaitTimer += Time.deltaTime;
                if (IdleWaitTimer >= C.IdleWaitTime)
                {
                    RootRotation.SetRandomTarget(new Vector3(0f, 0f, 0f), new Vector3(0f, 360f, 0f));
                    IdleWaitTimer = -1.0f;
                }
            }

            if (IdleWobbleNode != null)
            {
                float range = C.IdleWobbleFactor * 45f;

                IdleWobbleNode.localRotation = Quaternion.Euler(
                    IdleWobbleNode.localRotation.eulerAngles.x,
                    IdleWobbleNode.localRotation.eulerAngles.y,
                    wobble * range * IdleWobble
                    );

                if (IdleWobbleLeftFoot != null)
                {
                    IdleWobbleLeftFoot.localPosition = new Vector3(
                        IdleWobbleLeftFoot.localPosition.x,
                        (-wobble * 0.02f + 0.02f) * IdleWobble,
                        IdleWobbleLeftFoot.localPosition.z
                        );
                }

                if (IdleWobbleRightFoot != null)
                {
                    IdleWobbleRightFoot.localPosition = new Vector3(
                        IdleWobbleRightFoot.localPosition.x,
                        (wobble * 0.02f + 0.02f) * IdleWobble,
                        IdleWobbleRightFoot.localPosition.z
                        );
                }
            }
        }

        if (ActiveSpinNode != null)
        {
            if (ActiveSpinNode.Step(Time.deltaTime))
            {
                ActiveSpinNode.SetRandomTarget(new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 360f));
            }
        }

        for (int i = 0; i < ActiveRotateNodes.Length; ++i)
        {
            if (ActiveRotateNodes[i] == null)
            {
                continue;
            }

            if (ActiveRotateNodes[i].Step(Time.deltaTime))
            {
                ActiveRotateNodes[i].SetRandomTarget(new Vector3(140f, 0f, 0f), new Vector3(220f, 0f, 0f));
            }
        }

        // -----------------------------------------------------------------------------------
        // Ammo / Healing
        // -----------------------------------------------------------------------------------

        PowerupTimer += Time.deltaTime;
        if (PowerupTimer >= 1.0f)
        {
            foreach (PhxSoldier soldier in Soldiers)
            {
                soldier.AddHealth(C.SoldierHealth);
                soldier.AddAmmo(C.SoldierAmmo);
            }
            PowerupTimer = 0f;
        }
    }