I do not know what to do. Copy +pasting from the lecture gives similar errors.
using UnityEngine;
using UnityEngine.SceneManagement;
public class Rocket : MonoBehaviour {
[SerializeField] float rcsThrust = 100f;
[SerializeField] float MainThrust = 100f;
Rigidbody rigidBody;
AudioSource audioSource;
enum State { Alive, Dying, Transcending }
State state = State.Alive;
// Use this for initialization
void Start() {
rigidBody = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update() {
//stop sound on death
if (state == State.Alive) {
Thrust();
Rotate(); }
}
void OnCollisionEnter(Collision collision)
{
if (state != State.Alive) { return; }
{
switch (collision.gameObject.tag)
case "Friendly"://do nothing
print("Ok"); //todo remove
break;
case "Finish":
state = State.Transcending;
Invoke("LoadNextScene", 1f); //parameterize time
break;
default:
state = State.Dying;
print("Hit something deadly");
Invoke("LoadFirstLevel", 1f);
//kill player
break;
}
}
private void LoadFirstLevel()
{
SceneManager.LoadScene(0);
}
private void LoadNextScene()
{
SceneManager.LoadScene(1);
}
private void Thrust()
{
if (Input.GetKey(KeyCode.Space)) //can thrust while rotating
{
rigidBody.AddRelativeForce(Vector3.up * MainThrust);
if (!audioSource.isPlaying)
{
audioSource.Play(); //so it doesn't layer
} // same as if (audioSource.isPlaying == false)
}
else
{
audioSource.Stop();
}
}
private void Rotate()
{
rigidBody.freezeRotation = true; // take manual control of rotation
float rotationthisframe = rcsThrust * Time.deltaTime;
if (Input.GetKey(KeyCode.A)) {
transform.Rotate(Vector3.forward * rotationthisframe); }
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward * rotationthisframe); }
rigidBody.freezeRotation = false; // resume physics control of rotation
}
} }