Error in code that isn't resolved after resetting to an earlier branch in sourcetree :(

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. :frowning: 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

    }

}
1 Like

Hi,

Those errors which mention ambiguity are most likely the clue here. If I had to make a guess, based on the information provided, I’d suggest that you have more than one copy of the script files in your project. So, for example, there is more than one class named Rocket1, as such, the compiler doesn’t know to which you refer.

Have a look in your project directory and look for any duplicated files, they may have become nested.

If you can’t spot anything obvious, zip you project files share them with me and I will happily take a look for you.

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.

2 Likes

I was going to say the same, what has normally happened is in one commit you may have moved the rocket1 script to another folder and somehow its reinstated the original location as well.
I’ve been caught with that myself

1 Like

Sure enough, I had made a copy of the script in my assets, I was going to add a different rocket object and try & change some of the code to experiment. Once I deleted that script, my first script no longer has errors. Thank you so much!! Everything seems fine now.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms