コード例 #1
0
    private void FixedUpdate()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
        if (isShipEnabled)
        {
            float forwardSpeed    = Vector3.Project((Vector3)rb.velocity, transform.up).magnitude;
            float angleOfVelocity = Vector3.Angle((Vector3)rb.velocity, transform.up);
            if (angleOfVelocity > 90)
            {
                forwardSpeed = 0;
            }
            float possibleThrust = reactorForce * thrustByForwardSpeed.Evaluate(Mathf.Min(1, forwardSpeed / maximumForwardSpeed));

            if (Input.GetButton("ReactorInput") && can_fly)
            {
                ui_manager.modify_fuel(-fuelCost);
                rb.velocity += possibleThrust * (Vector2)transform.up * Time.deltaTime;
                rb.velocity += -Vector2.up * gravityUnderThrust * Time.deltaTime;
                if (Input.GetKey(KeyCode.A))
                {
                    rb.rotation += rotationSpeedUnderThrust * Time.deltaTime;
                }
                if (Input.GetKey(KeyCode.D))
                {
                    rb.rotation -= rotationSpeedUnderThrust * Time.deltaTime;
                }
            }
            else
            {
                rb.velocity += -Vector2.up * normalGravity * Time.deltaTime;
                if (Input.GetKey(KeyCode.A))
                {
                    rb.rotation      += rotationSpeed * Time.deltaTime;
                    rb.freezeRotation = true;
                }
                if (Input.GetKeyUp(KeyCode.A))
                {
                    rb.freezeRotation = false;
                }
                if (Input.GetKey(KeyCode.D))
                {
                    rb.rotation      -= rotationSpeed * Time.deltaTime;
                    rb.freezeRotation = true;
                }
                if (Input.GetKeyUp(KeyCode.D))
                {
                    rb.freezeRotation = false;
                }
            }
            float vel = rb.velocity.magnitude;
            vel         = Mathf.Lerp(vel, 0, frictionByAngle.Evaluate(angleOfVelocity / 180) * friction * Time.deltaTime);
            rb.velocity = rb.velocity.normalized * vel;
            mag         = rb.velocity.magnitude;
        }
    }
コード例 #2
0
 private void Update()
 {
     if (playerLanded && shipScr.vuelta)
     {
         uiScr.modify_fuel(.003f);
         delayToDeployEgg -= Time.deltaTime;
         if (delayToDeployEgg <= 0 && shipScr.numMinerals > 0)
         {
             shipScr.numMinerals -= 1;
             uiScr.SetUIEggs(shipScr.numMinerals);
             uiScr.modify_score(1);
             delayToDeployEgg = oldDelay;
         }
         if (shipScr.numMinerals == 0)
         {
             animSemaforo.SetBool("Enabled", true);
             semaforoCounter -= Time.deltaTime;
             if (semaforoCounter <= 0)
             {
                 shipScr.enabled = false;
                 ship.parent     = destination;
                 anim.SetBool("PlatformUp", true);
                 StartCoroutine(LoadLevel("Lvl_Iteracion"));
             }
         }
     }
 }
コード例 #3
0
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (collision.gameObject.layer == 10 && current_fuel >= 0 && uiScr.fuel < 1)
     {
         current_fuel -= .001f;
         uiScr.modify_fuel(.001f);
         UpdateGauge();
     }
 }