Esempio n. 1
0
    void FixedUpdate()
    {
        switch (currentThrustState)
        {
        case ThrustState.Off:


            break;

        case ThrustState.On:
            if (fuelAmount > 0.0f)
            {
                float usedFuel = fuelConsumption * Time.fixedDeltaTime * thrust / maxThrust;

                fuelAmount -= usedFuel;
                rb.mass    -= usedFuel;

                thrustDirection = transform.up * thrust;
                //Debug.DrawRay(transform.position, thrustDirection, Color.green);

                rb.AddForceAtPosition(thrustDirection, centerOfThrust.position, ForceMode.Force);

                //GimbalThruster();
            }
            else
            {
                fireParticle.Stop();
                currentThrustState = ThrustState.Off;
            }


            break;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (currentThrustState == ThrustState.On)
            {
                fireParticle.Stop();

                currentThrustState = ThrustState.Off;
            }
            else if (currentThrustState == ThrustState.Off)
            {
                fireParticle.Play();

                currentThrustState = ThrustState.On;
            }
        }

        if (Input.GetKey(KeyCode.UpArrow))
        {
            thrust += ((maxThrust / 100) * 30) * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            thrust -= ((maxThrust / 100) * 30) * Time.deltaTime;
        }

        thrust = Mathf.Clamp(thrust, 0f, maxThrust);

        thrustAmount.color      = Color.Lerp(Color.blue, Color.red, thrust / maxThrust);
        thrustAmount.fillAmount = thrust / maxThrust;
    }