コード例 #1
0
    //FixedUpdate por usar vectores, fuerzas
    void FixedUpdate()
    {
        //Updating the player move
        float shootingState = CrossPlatformInputManager.GetMood();

        //Debug.Log("My x: " + transform.position.x + " My y: " + transform.position.y);
        if ((moodState == 0 && shootingState > 0.5) || (moodState == 1 && shootingState < 0.5))
        {
            setShootingState(shootingState);
        }

        Vector2 moveVector = new Vector2(CrossPlatformInputManager.GetAxis("Horizontal"),
                                         CrossPlatformInputManager.GetAxis("Vertical")) * speedForce;
        bool isBoost = CrossPlatformInputManager.GetButton("Boton");

        playerBody.AddForce(moveVector * (isBoost? increaseBoost: defaultBoost));

        if (isBoost)
        {
            SoundEffectsHelper.Instance.MakeBoostSound();
        }

        //Updating the player rotation
        //playerBody.MoveRotation(playerBody.rotation+CrossPlatformInputManager.GetAxis("VerticalRot")*rotationvelocity);
        float  LO = CrossPlatformInputManager.GetAxis("VerticalRot");
        float  LA = CrossPlatformInputManager.GetAxis("HorizontalRot");
        double B  = Math.Atan(LO / LA) * 180 / Math.PI;

        if (LA < 0)
        {
            B += 180;
        }
        B += (-90);
        if (!B.Equals(Double.NaN))
        {
            transform.rotation = Quaternion.Euler(0, 0, (float)B);
        }
        //Updating the Health bar rotation according to the player rotation
        Quaternion rot = healthBar.rotation;
        float      z   = playerBody.rotation + CrossPlatformInputManager.GetAxis("VerticalRot") * rotationvelocity;

        rot = Quaternion.Euler(0, 0, z);
        healthBar.rotation = rot;

        //Fire Validation
        //before Input.GetKeyDown(KeyCode.Space)

        if (moodState == 1 && (LA != 0 || LO != 0))
        {
            coolDown(true);
            //cool = true;
        }
        if (currentBurst < 75)
        {
            coolDown(false);
            //cool = false;
        }

        if (shootingTimer < 0 && !shootingBlocked)
        {
            if (LA != 0 || LO != 0)
            {
                shootingTimer = fireDelay;
                CmdFire();
                //SoundEffectsHelper.Instance.MakePlayerShotSound();
                isShooting = false;
            }
        }

        //Restrict the ship to the camara's bounderies

        Vector3 pos = transform.position;

        if (pos.y + shipBounderyRadious > camViewSize)
        {
            pos.y = camViewSize - shipBounderyRadious;
            transform.position = pos;
        }
        if (pos.y - shipBounderyRadious < -camViewSize)
        {
            pos.y = -camViewSize + shipBounderyRadious;
            transform.position = pos;
        }

        float screenRatio = (float)Screen.width / (float)Screen.height;
        float widthOrtho  = camViewSize * screenRatio;

        if (pos.x + shipBounderyRadious > widthOrtho)
        {
            pos.x = widthOrtho - shipBounderyRadious;
            transform.position = pos;
        }
        if (pos.x - shipBounderyRadious < -widthOrtho)
        {
            pos.x = -widthOrtho + shipBounderyRadious;
            transform.position = pos;
        }

        //Code for limiting movement by boundaries

        /*Vector3 pos = transform.position;
         * if(pos.y > HEIGHT) {
         *      pos.y = HEIGHT;
         *      //pos.y = camViewSize - shipBounderyRadious;
         *      transform.position = pos;
         * }
         *
         * if(pos.y < -HEIGHT) {
         *      pos.y = -HEIGHT;
         *      //pos.y = -camViewSize + shipBounderyRadious;
         *      transform.position = pos;
         * }*/

        //float screenRatio  = (float)Screen.width / (float)Screen.height;
        //float widthOrtho = camViewSize * screenRatio;
        if (pos.x > WIDTH)
        {
            pos.x = WIDTH;
            //pos.x = camViewSize - shipBounderyRadious;
            transform.position = pos;
        }

        if (pos.x < -WIDTH)
        {
            pos.x = -WIDTH;
            //pos.x = -camViewSize + shipBounderyRadious;
            transform.position = pos;
        }

        //end limit movement section

        /*Quaternion rot = transform.rotation;
         * float z = rot.eulerAngles.z;
         *
         * z-= CrossPlatformInputManager.GetAxis("VerticalRot") *rotationvelocity;
         * //Debug.Log(CrossPlatformInputManager.GetAxis("VerticalRot")+" rota: "+ rotationvelocity);
         *
         * rot = Quaternion.Euler(0,0,z);
         * transform.rotation = rot;
         * Vector3 pos2 = transform.position;
         * Vector3 velocity = new Vector3(CrossPlatformInputManager.GetAxis("Horizontal") * speedForce * Time.deltaTime,
         *      CrossPlatformInputManager.GetAxis("Vertical") * speedForce * Time.deltaTime,0) * (isBoost? increaseBoost: defaultBoost);
         * pos2 += rot * velocity;
         * transform.position = pos2;*/
    }