The issue is with my code. I don’t even know what happened, but suddenly I have 11 errors in it, I don’t recall changing anything and I’m not skilled enough in C# yet to know what’s going on. Resetting current branch did not resolve this issue. As suggested in the Q&A section, where I also submitted this issue, I followed these steps: “select your desired commit and click the right mouse button. Select ;Reset current branch to this commit’ (Using Mode: Mixed).” Everything was working fine til I got about 90% done with this lecture, I paused it, saved my work, then came back to it later on, and now this.
full code below:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket1 : MonoBehaviour {
[SerializeField] float rcsThrust = 100f; //SerializeField allows us to change thrust in the Inspector
//rcs - reaction control system
//100 will be the default value, will appear in the rocket script component
[SerializeField] float mainThrust = 100f; //makes main thrust adjustable
Rigidbody rigidBody; // add reference to rigid body
AudioSource audioSource;
// Use this for initialization
void Start () {
rigidBody = GetComponent<Rigidbody>(); //gives access to rigid body
audioSource = GetComponent<AudioSource>();
}
// Update is called once per frame
void Update () {
Thrust();
Rotate();
}
void OnCollisionEnter(Collision collision) //whenever rocket hits object not tagged 'friendly'
{
switch (collision.gameObject.tag)
{
case "friendly": //tags are case sensitive
// friendly = do nothing to rocket
print("OK");
break;
case "fuel":
// fuel = rocket gets fuel
print("fueling complete");
break;
default:
print("RIP");
break;
//default objects cause damage to rocket
}
}
private void Thrust()
{
if (Input.GetKey(KeyCode.Space)) //can thrust while rotating
{
rigidBody.AddRelativeForce(Vector3.up * mainThrust); //thrust
if (!audioSource.isPlaying) //exclamation point negates, so this means 'if audio source is NOT playing'
{
audioSource.Play(); //rocket sound begins when thrust begins
}
}
else
{
audioSource.Stop();
}
}
private void Rotate()
{
rigidBody.freezeRotation = true; // take manual control of rotation
float rcsThrust = 100f; //100f is floating point number
float rotationThisFrame = rcsThrust * Time.deltaTime; //when this line placed here, becomes available to entire function below
if (Input.GetKey(KeyCode.A))// can rotate left OR right, not both at same time
{
transform.Rotate(Vector3.forward * rotationThisFrame); //rotate left/anticlockwise around Z axis, aka vector3.forward
}
else if (Input.GetKey(KeyCode.D))
{
transform.Rotate(-Vector3.forward * rotationThisFrame); //rotate right/clockwise around Z axis
}
rigidBody.freezeRotation = false; //resumes physics control
}
}