when ever my rocket dies it just sit still and when i die this pops up and ideas? Here is my code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Rocket : MonoBehaviour{
[SerializeField] float rcsthrust = 100f;
[SerializeField] float mainThrust = 100f;
[SerializeField] AudioClip mainEngine;
Rigidbody rigidbody;
AudioSource audioSource;
// Start is called before the first frame update
void Start()
{
rigidbody = GetComponent< Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
enum State { Alive, Dying, Transending }
State state = State.Alive;
// Update is called once per frame
void Update()
{
if(state == State.Alive)
{
processinput();
thrust();
NewMethod();
}
}
private void NewMethod()
{
processinput();
}
private void processinput()
{
rigidbody.freezeRotation = true; // take control of rotation
float rotaionThisFrame = rcsthrust * Time.deltaTime;
if (Input.GetKey(KeyCode.A))
{
transform.Rotate(Vector3.forward * rotaionThisFrame);
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward*rotaionThisFrame);
}
rigidbody.freezeRotation = false;//resume physics of rotaion
}
void OnCollisionEnter(Collision collision)
{
if (state != State.Alive)
{
return;
}
switch (collision.gameObject.tag)
{
case "friendly":
//do nothing
print("ok");// remove it later
break;
case "Finish":
state = State.Transending;
print("Hit Finish");// remove it later
Invoke("Loadnextscene", 1f);
break;
default:
print("Hit something deadly");
state = State.Dying;
Invoke("LoadfirstLevel", 1f);
break;
}
}
private static void loadfirstlevel()
{
SceneManager.LoadScene(0);
}
private void Loadnextscene()
{
SceneManager.LoadScene(1); // allow for more then 2 levels
}
private void thrust()
{
if (Input.GetKey(KeyCode.W))
{
rigidbody.AddRelativeForce(Vector3.up * mainThrust);
if (audioSource.isPlaying == false)// so it does not layer
{
audioSource.Play();
}
}
else
{
audioSource.Stop();
}
}
}