Hi, class how can I stop the game from restarting at the beginning of the game? Any insight is very appreciated
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LandingPad: MonoBehaviour
{
}
private bool landed = true;
private GameController gameController;
// Update is called once per frame
void Update()
{
if (isControlEnabled)
{
ProcessTranslation();
ProcessRotation();
ProcessFiring();
}
}
void OnPlayerDeath()
{
isControlEnabled = false;
gameController.GameOver();
}
private void Start()
{
gameController = FindObjectOfType<GameController>();
}
private void ProcessRotation()
{
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToControlThrow = yThrow * controlPitchFactor;
float pitch = pitchDueToPosition + pitchDueToControlThrow;
float yaw = transform.localPosition.x * positionYawFactor;
float roll = xThrow * controlRollFactor;
transform.localRotation = Quaternion.Euler(pitch, yaw, roll);
}
private void ProcessTranslation()
{
xThrow = CrossPlatformInputManager.GetAxis("Horizontal");
yThrow = CrossPlatformInputManager.GetAxis("Vertical");
float xOffset = xThrow * controlSpeed * Time.deltaTime;
float yOffset = yThrow * controlSpeed * Time.deltaTime;
float rawXPos = transform.localPosition.x + xOffset;
float clampedXPos = Mathf.Clamp(rawXPos, -xRange, xRange);
float rawYPos = transform.localPosition.y + yOffset;
float clampedYPos = Mathf.Clamp(rawYPos, -yRange, yRange);
transform.localPosition = new Vector3(clampedXPos, clampedYPos, transform.localPosition.z);
}
void OnPlayerLanding()
{
isControlEnabled = false;
if (!landed)
{
gameController.GameOver();
}
}
void OnPlayerTakeOff()
{
isControlEnabled = true;
landed = false;
}
void ProcessFiring()
{
if (CrossPlatformInputManager.GetButton("Fire"))
{
SetGunsActive(true);
}
else
{
SetGunsActive(false);
}
}
private void SetGunsActive(bool isActive)
{
foreach (GameObject gun in guns) // care may affect death FX
{
var emissionModule = gun.GetComponent<ParticleSystem>().emission;
emissionModule.enabled = isActive;
}
}
}