Пример #1
0
    // Update is called once per frame
    void Update()
    {
        /*I use a switch statement to determine what the defender should do in each state
         */
        switch (state)
        {
        case Defender_State.RESTING:

            /* If the player is IDLE, I make sure the capsule collider is correctly facing up along the Y axis. This
             * is so I can use the players as a wall to try and block the user from shooting. I then check to make sure
             * the correct animation is playing. If the defenderIdle animation is not playing, I play it.
             * I then make sure the defender looks at the player
             */
            capsuleCollider.direction = 1;
            if (!animation.IsPlaying("defenderIdle"))
            {
                animation.Play("defenderIdle");
            }

            transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));

            float distanceBall = (transform.position - sphere.transform.position).magnitude;

            if (distanceBall < 10.0f)
            {
                state = DefenderScript.Defender_State.RESTING;
            }
            break;
        }
    }
Пример #2
0
 // Use this for initialization
 void Start()
 {
     initial_Position = transform.position;
     state            = Defender_State.RESTING; //I initially set the defender to be idle
     animation["defenderIdle"].speed = 1.0f;
 }