Example #1
0
    void Avoidance(string previousState)
    {
        ChangeState("Avoiding");
        // Begin the first part of avoiding
        if (avoidanceStage == 1)
        {
            // Rotate to the left for a designer set amount of time
            stageTimer = resetTimer;
            motor.RotateLeft();

            // Go to the next stage
            if (stageTimer <= 0)
            {
                avoidanceStage = 2;
            }
        }
        if (avoidanceStage == 2)
        {
            // Move forward for a designer set amount of time
            stageTimer      = resetTimer;
            motor.moveSpeed = restoreSpeed;
            motor.MoveForward();
            if (stageTimer <= 0)
            {
                avoidanceStage = 3;
            }
        }
        if (avoidanceStage == 3)
        {
            // Rotate to the right for set amount of time
            stageTimer = resetTimer;
            motor.RotateRight();
            if (stageTimer <= 0)
            {
                avoidanceStage = 0;
                ChangeState(previousState);
            }
        }
    }
Example #2
0
 // Update is called once per frame
 void Update()
 {
     // Countdown
     fire.timer -= Time.deltaTime;
     // Check if the player is pressing w or the up arrow
     if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
     {
         // Use the MoveForward function on the TankMotor script
         motor.MoveForward();
     }
     // Check if the player is pressing s or the down arrow
     if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
     {
         // Use the MoveBackwards function on the TankMotor script
         motor.MoveBackwards();
     }
     // Check if the player is pressing a or the left arrow
     if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
     {
         // Use the RotateLeft function on the TankMotor script
         motor.RotateLeft();
     }
     // Check if the player is pressing d or the right arrow
     if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
     {
         // Use the RotateRight function on the TankMotor script
         motor.RotateRight();
     }
     // Check if the count down is less than or equal to 0
     if (fire.timer <= 0)
     {
         // Check if the player is pressing space
         if (Input.GetKeyDown(KeyCode.Space))
         {
             // Use the Fire function on the Shoot script
             fire.Fire();
         }
     }
 }