// Update is called once per frame void Update() { if (inmunityLight.enabled) { inmunityTimer += Time.deltaTime; if (inmunityTimer > inmunityDuration) { inmunityLight.enabled = false; } } bool mustBrake = true; foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Stationary) { if (touch.position.y > (Screen.height - Screen.height / 3) && (touch.position.x > (Screen.width - Screen.width / fractionOfTouch) || touch.position.x < (Screen.width / fractionOfTouch))) { mustBrake = false; if (thruster < maxThruster) { thruster += thrusterInc; } Vector3 newForce = transform.forward * -throttle * Time.deltaTime; if ((rigidBody.velocity + newForce).magnitude < maxForce) { rigidBody.AddForce(newForce); } else { rigidBody.velocity *= maxSpeedBrake; } } else if (touch.position.y < (Screen.height - Screen.height / 3) && touch.position.y > (Screen.height / 3) && touch.position.x > (Screen.width - Screen.width / fractionOfTouch)) { transform.RotateAround(transform.position, transform.up, Time.deltaTime * rotSpeed); } else if (touch.position.y < (Screen.height - Screen.height / 3) && touch.position.y > (Screen.height / 3) && touch.position.x > (Screen.width - Screen.width / fractionOfTouch)) { transform.RotateAround(transform.position, transform.up, Time.deltaTime * rotSpeed); } else if (touch.position.y < (Screen.height - Screen.height / 3) && touch.position.y > (Screen.height / 3) && touch.position.x < (Screen.width / fractionOfTouch)) { transform.RotateAround(transform.position, transform.up, Time.deltaTime * -rotSpeed); } else { weaponsScr.fire(); } } } if (mustBrake) { if (thruster > 0.0f) { thruster -= thrusterInc * 0.9f; } if (Input.GetKey("down")) { rigidBody.velocity *= inverseInertia * 0.985f; } else { rigidBody.velocity *= inverseInertia; } } if (transform.position.x < xMin) { transform.position = new Vector3(xMax, 0.0f, transform.position.z); } if (transform.position.x > xMax) { transform.position = new Vector3(xMin, 0.0f, transform.position.z); } if (transform.position.z < zMin) { transform.position = new Vector3(transform.position.x, 0.0f, zMax); } if (transform.position.z > zMax) { transform.position = new Vector3(transform.position.x, 0.0f, zMin); } if (transform.position.y != 0.0f) { transform.position = new Vector3(transform.position.x, 0.0f, transform.position.z); } ParticleSystem.EmissionModule em = thrusterPart.emission; em.rateOverTime = thruster; }