Пример #1
0
    private void Update()
    {
        float pFuel = probe.GetFuel();

        if (pFuel < 0)
        {
            pFuel = 0;
        }
        float ratio = pFuel / MaxFuel;

        CurrentProbeFuel.rectTransform.localScale = new Vector3(ratio, 1, 1);
        FuelPercentage.text = ((int)System.Math.Round((double)(ratio * 100))).ToString() + '%';
    }
Пример #2
0
    void FixedUpdate()
    {
        Cooldown -= Time.deltaTime;                       //decrement cooldown each FixedUpdate

        if (probe.GetFuelRounded() > 0 && Cooldown <= 0f) //only fire if fuel and cooldown allow
        {
            if (Input.GetKey(KeyCode.Space))
            {
                GameObject newProjectile = Instantiate(projectile, transform.position, transform.rotation);
                newProjectile.GetComponent <ProjectileObject>().ParentSpeed = probe.GetCurrentSpeed();
                probe.SetFuel(probe.GetFuel() - Random.Range(1f, 100f));
            }
            Cooldown = CooldownTime; //enable cooldown on firing
        }
    }
Пример #3
0
 private void Start()
 {
     probe     = GameObject.FindGameObjectWithTag("Player").GetComponent <ProbeObject>();
     StartFuel = probe.GetFuel();
     MaxFuel   = StartFuel;
 }
Пример #4
0
    void FixedUpdate()
    {
        //purpose: conducts probe movement if certain key(s) are pressed

        if (probe.GetFuel() > 0)
        {
            if (Input.GetKey(KeyCode.LeftShift) & Input.GetKey(KeyCode.W)) //if both keys W and LShift are held
            {
                //apply additional force in direction of local Z axis
                rb.AddRelativeForce(0, 0, superSpeed * Time.deltaTime, ForceMode.Acceleration);

                //update fuel
                probe.SetFuel(probe.GetFuel() - superFuelRate);

                //enable engine effects
                lensflare.GetComponent <LensFlare>().brightness = 1f;
                particles.GetComponent <ParticleSystem>().Play();
            }
            else if (Input.GetKey(KeyCode.S))                //if key S is held
            {
                if (previousSpeed > probe.GetCurrentSpeed()) //slow down whilst speed is decreasing
                {
                    //slow down probe
                    rb.AddRelativeForce(0, 0, -moveSpeed * Time.deltaTime, ForceMode.Acceleration);

                    //update fuel
                    probe.SetFuel(probe.GetFuel() - superFuelRate);

                    //disable engine effects
                    lensflare.GetComponent <LensFlare>().brightness = 0f;
                    particles.GetComponent <ParticleSystem>().Stop();
                }
            }
            else if (Input.GetKey(KeyCode.Q)) //if key Q is held
            {
                //bring probe to a stop
                rb.velocity = new Vector3(0, 0, 0);

                //disable engine effects
                lensflare.GetComponent <LensFlare>().brightness = 0f;
                particles.GetComponent <ParticleSystem>().Stop();
            }
            else if (Input.GetKey(KeyCode.W)) //if key W is held
            {
                //apply force in positive direction of local Z axis
                rb.AddRelativeForce(0, 0, moveSpeed * Time.deltaTime, ForceMode.Acceleration);

                //update fuel
                probe.SetFuel(probe.GetFuel() - normalFuelRate);

                //enable engine effects
                lensflare.GetComponent <LensFlare>().brightness = 0.75f;
                particles.GetComponent <ParticleSystem>().Play();
            }
            else
            {
                //disable all engine effects
                lensflare.GetComponent <LensFlare>().brightness = 0;
                particles.GetComponent <ParticleSystem>().Stop();
            }
        }
        else
        {
            //disable all engine effects
            lensflare.GetComponent <LensFlare>().brightness = 0;
            particles.GetComponent <ParticleSystem>().Stop();
        }

        //manage fuel tasks
        if (fuelcounter != null)
        {
            fuelcounter.GetComponent <Text>().text = "Fuel: " + probe.GetFuelRounded().ToString();
        }

        //manage speed tasks
        if (speedometer != null)
        {
            speedometer.GetComponent <Text>().text = "Speed: " + probe.GetCurrentSpeed().ToString() + " KP/H";
        }

        //store current speed to check in the next FixedUpdate call so that the script can ensure the slowdown function doesn't reverse the probe
        previousSpeed = probe.GetCurrentSpeed();

        MoveCamera();
    }