Exemple #1
0
    void Update()
    {
        if(enable){
                 topSpeedForward = 3.0f; 				// top speed of forward
                 topSpeedReverse = -2.0f; 				// top speed of reverse
                 accelerationRate = 1.0f; 				// rate at which top movement speed is reached
                 rotationRate     = 20.0f; 				// rate at whitch top rotation speed is reached
                 topRotationSpeedRight =6.0f;			// top speed rotation right
                 topRotationSpeedLeft  =-6.0f;			// mtop speed rotation left
                 brakeRate          = 0.005f; 			// rate at which speed is lost when not accelerating
            }else{
                 topSpeedForward = 0.0f; 				// top speed of forward
                 topSpeedReverse = 0.0f; 				// top speed of reverse
                 accelerationRate = 0.0f; 				// rate at which top movement speed is reached
                 rotationRate     = 0.0f; 				// rate at whitch top rotation speed is reached
                 topRotationSpeedRight =0.0f;			// top speed rotation right
                 topRotationSpeedLeft  =0.0f;			// mtop speed rotation left
                 brakeRate          = 0.0f; 			// rate at which speed is lost when not accelerating
                 currentMoveSpeed     = 0.0f; 			// stores current move speed
                 currentRotationSpeed = 0.0f;
            }

            if(freeze){
                //start timer for defrosting
                 FrozenTimer();
            }

            if(isControllable){
                //As long as the joystick has been moved in x or y
                if(moveJoystick.position.y >0.5 || Input.GetKey(KeyCode.UpArrow)){
                   //FORWARD
                   Acceleration("forward");
                   _characterState = AnimationsState.Forward;

                   if(moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow)){
                      //FORWARD LEFT
                      Rotation("left");
                   }else if(moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow)){
                      //FORWARD RIGHT
                      Rotation("right");
                   }
                }else if(moveJoystick.position.y <-0.5 || Input.GetKey(KeyCode.DownArrow)){
                     //BACKWARD
                 	 Acceleration("reverse");
                     _characterState = AnimationsState.Forward;
                   if(moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow)){
                     //BACKWARD LEFT
                     Rotation("left");
                   }else if(moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow)){
                     //BACKWARD RIGHT
                     Rotation("right");
                   }
                }else if(moveJoystick.position.x >0.5 || Input.GetKey(KeyCode.RightArrow)){
                     //RIGHT
                     _characterState = AnimationsState.Right;
                     Rotation("right");
                }else if(moveJoystick.position.x <-0.5 || Input.GetKey(KeyCode.LeftArrow)){
                     //LEFT
                     _characterState = AnimationsState.Left;
                     Rotation("left");
                }else{
                     //IDLE
                     if(LifeScript.dead){
                        _characterState = AnimationsState.Dead;
                        OnEndGame();
                     }else{
                        if(ShootScript.FireBtn){
                            _characterState = AnimationsState.Shoot;
                         }else{
                            _characterState = AnimationsState.Idle;
                         }
                     }

                }
                var pos = Tracking.transform.localPosition;
                pos.z = Mathf.Clamp(moveSlider.distanceSlider,3.0f,35.0f);
                Tracking.transform.localPosition=pos;
            }

            switch(_characterState){
                case AnimationsState.Idle:     anim.idle();
                                               anim.shoot(false);
                                               break;
                case AnimationsState.Forward:  anim.fwd(true);
                                               break;
                case AnimationsState.Backward: anim.bwd(true);
                                               break;
                case AnimationsState.Left:     anim.left(true);
                                               break;
                case AnimationsState.Right:    anim.right(true);
                                               break;
                case AnimationsState.Shoot:    anim.shoot(true);
                                               break;
                case AnimationsState.Dead:     anim.dead();
                                               break;
            }
    }
    void Update()
    {
        if(isControllable){
                //As long as the joystick has been moved in x or y
                if(moveJoystick.position.y >0.5 || Input.GetKey(KeyCode.UpArrow)){
                   //FORWARD
                   Acceleration("forward");
                   _characterState = AnimationsState.Forward;

                   if(moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow)){
                      //FORWARD LEFT
                      Rotation("left");
                   }else if(moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow)){
                      //FORWARD RIGHT
                      Rotation("right");
                   }
                }else if(moveJoystick.position.y <-0.5 || Input.GetKey(KeyCode.DownArrow)){
                     //BACKWARD
                 	 Acceleration("reverse");
                     _characterState = AnimationsState.Backward;
                   if(moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow)){
                     //BACKWARD LEFT
                     Rotation("left");
                   }else if(moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow)){
                     //BACKWARD RIGHT
                     Rotation("right");
                   }
                }else if(moveJoystick.position.x >0.5 || Input.GetKey(KeyCode.RightArrow)){
                     //RIGHT
                     _characterState = AnimationsState.Right;
                     Rotation("right");
                }else if(moveJoystick.position.x <-0.5 || Input.GetKey(KeyCode.LeftArrow)){
                     //LEFT
                     _characterState = AnimationsState.Left;
                     Rotation("left");
                }else{
                     //IDLE
                     if(FireSingle.FireBtn){
                        _characterState = AnimationsState.Shoot;
                     }else{
                        _characterState = AnimationsState.Idle;
                     }

                }
                var pos = Tracking.transform.localPosition;
                pos.z = Mathf.Clamp(moveSlider.distanceSlider,3.0f,35.0f);
                Tracking.transform.localPosition=pos;
            }

            switch(_characterState){
                case AnimationsState.Idle:     anim.idle();
                                               anim.shoot(false);
                                               break;
                case AnimationsState.Forward:  anim.fwd(true);
                                               break;
                case AnimationsState.Backward: anim.bwd(true);
                                               break;
                case AnimationsState.Left:     anim.left(true);
                                               break;
                case AnimationsState.Right:    anim.right(true);
                                               break;
                case AnimationsState.Shoot:    anim.shoot(true);
                                               break;
            }
    }
Exemple #3
0
    void Update()
    {
        if (enable)
        {
            topSpeedForward       = 3.0f;                                       // top speed of forward
            topSpeedReverse       = -2.0f;                                      // top speed of reverse
            accelerationRate      = 1.0f;                                       // rate at which top movement speed is reached
            rotationRate          = 20.0f;                                      // rate at whitch top rotation speed is reached
            topRotationSpeedRight = 6.0f;                                       // top speed rotation right
            topRotationSpeedLeft  = -6.0f;                                      // mtop speed rotation left
            brakeRate             = 0.005f;                                     // rate at which speed is lost when not accelerating
        }
        else
        {
            topSpeedForward       = 0.0f;                                       // top speed of forward
            topSpeedReverse       = 0.0f;                                       // top speed of reverse
            accelerationRate      = 0.0f;                                       // rate at which top movement speed is reached
            rotationRate          = 0.0f;                                       // rate at whitch top rotation speed is reached
            topRotationSpeedRight = 0.0f;                                       // top speed rotation right
            topRotationSpeedLeft  = 0.0f;                                       // mtop speed rotation left
            brakeRate             = 0.0f;                                       // rate at which speed is lost when not accelerating
            currentMoveSpeed      = 0.0f;                                       // stores current move speed
            currentRotationSpeed  = 0.0f;
        }

        if (freeze)
        {
            //start timer for defrosting
            FrozenTimer();
        }

        if (isControllable)
        {
            //As long as the joystick has been moved in x or y
            if (moveJoystick.position.y > 0.5 || Input.GetKey(KeyCode.UpArrow))
            {
                //FORWARD
                Acceleration("forward");
                _characterState = AnimationsState.Forward;

                if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
                {
                    //FORWARD LEFT
                    Rotation("left");
                }
                else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
                {
                    //FORWARD RIGHT
                    Rotation("right");
                }
            }
            else if (moveJoystick.position.y < -0.5 || Input.GetKey(KeyCode.DownArrow))
            {
                //BACKWARD
                Acceleration("reverse");
                _characterState = AnimationsState.Forward;
                if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
                {
                    //BACKWARD LEFT
                    Rotation("left");
                }
                else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
                {
                    //BACKWARD RIGHT
                    Rotation("right");
                }
            }
            else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
            {
                //RIGHT
                _characterState = AnimationsState.Right;
                Rotation("right");
            }
            else if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
            {
                //LEFT
                _characterState = AnimationsState.Left;
                Rotation("left");
            }
            else
            {
                //IDLE
                if (LifeScript.dead)
                {
                    _characterState = AnimationsState.Dead;
                    OnEndGame();
                }
                else
                {
                    if (ShootScript.FireBtn)
                    {
                        _characterState = AnimationsState.Shoot;
                    }
                    else
                    {
                        _characterState = AnimationsState.Idle;
                    }
                }
            }
            var pos = Tracking.transform.localPosition;
            pos.z = Mathf.Clamp(moveSlider.distanceSlider, 3.0f, 35.0f);
            Tracking.transform.localPosition = pos;
        }

        switch (_characterState)
        {
        case AnimationsState.Idle:     anim.idle();
            anim.shoot(false);
            break;

        case AnimationsState.Forward:  anim.fwd(true);
            break;

        case AnimationsState.Backward: anim.bwd(true);
            break;

        case AnimationsState.Left:     anim.left(true);
            break;

        case AnimationsState.Right:    anim.right(true);
            break;

        case AnimationsState.Shoot:    anim.shoot(true);
            break;

        case AnimationsState.Dead:     anim.dead();
            break;
        }
    }
    void Update()
    {
        if (isControllable)
        {
            //As long as the joystick has been moved in x or y
            if (moveJoystick.position.y > 0.5 || Input.GetKey(KeyCode.UpArrow))
            {
                //FORWARD
                Acceleration("forward");
                _characterState = AnimationsState.Forward;

                if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
                {
                    //FORWARD LEFT
                    Rotation("left");
                }
                else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
                {
                    //FORWARD RIGHT
                    Rotation("right");
                }
            }
            else if (moveJoystick.position.y < -0.5 || Input.GetKey(KeyCode.DownArrow))
            {
                //BACKWARD
                Acceleration("reverse");
                _characterState = AnimationsState.Backward;
                if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
                {
                    //BACKWARD LEFT
                    Rotation("left");
                }
                else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
                {
                    //BACKWARD RIGHT
                    Rotation("right");
                }
            }
            else if (moveJoystick.position.x > 0.5 || Input.GetKey(KeyCode.RightArrow))
            {
                //RIGHT
                _characterState = AnimationsState.Right;
                Rotation("right");
            }
            else if (moveJoystick.position.x < -0.5 || Input.GetKey(KeyCode.LeftArrow))
            {
                //LEFT
                _characterState = AnimationsState.Left;
                Rotation("left");
            }
            else
            {
                //IDLE
                if (FireSingle.FireBtn)
                {
                    _characterState = AnimationsState.Shoot;
                }
                else
                {
                    _characterState = AnimationsState.Idle;
                }
            }
            var pos = Tracking.transform.localPosition;
            pos.z = Mathf.Clamp(moveSlider.distanceSlider, 3.0f, 35.0f);
            Tracking.transform.localPosition = pos;
        }

        switch (_characterState)
        {
        case AnimationsState.Idle:     anim.idle();
            anim.shoot(false);
            break;

        case AnimationsState.Forward:  anim.fwd(true);
            break;

        case AnimationsState.Backward: anim.bwd(true);
            break;

        case AnimationsState.Left:     anim.left(true);
            break;

        case AnimationsState.Right:    anim.right(true);
            break;

        case AnimationsState.Shoot:    anim.shoot(true);
            break;
        }
    }