My Second Level Won't Load

I followed along and added in the code just like Ben did but my Level 2 will not load when my rocket hits the landing pad. It will flash like it is going to load but instead it goes back to the launch pad for Level 1.

~

using UnityEngine;
using UnityEngine.SceneManagement;

public class Rocket : MonoBehaviour {

    [SerializeField] float rcsThrust = 100f;
    [SerializeField] float mainThrust = 100f;

    Rigidbody rigidBody;
    AudioSource audioSource; 

	// Use this for initialization
	void Start () {
        rigidBody = GetComponent<Rigidbody>();
        audioSource = GetComponent<AudioSource>();
	}
	
	// Update is called once per frame
	void Update () {
        Thrust();
        Rotate();
    }
    void OnCollisionEnter(Collision collision)
    {
        switch (collision.gameObject.tag)
        {
            case "Friendly":
                // do nothing
                break;
            case "Finish":
                print("Hit finish"); // todo remove 
                SceneManager.LoadScene(1);
                break;
            default:
                print("Dead");
                SceneManager.LoadScene(0);
                break;
        }
    }

    private void Thrust()
    {
        if (Input.GetKey(KeyCode.Space))// can thrust while rotating
        {
            rigidBody.AddRelativeForce(Vector3.up * mainThrust);

            if (audioSource.isPlaying == false) //so it doesn't layer
            {
                audioSource.Play();
            }
        }
        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
    }
}

~

I also need to know how to start from a different location on the sourcetree. In trying stuff to fix my issue, I somehow lost something (prefab?) so I just need to back to my previous save that I did in sourcetree but not sure how to do that.

Have you added the scene to your build settings?

Yes I did add them to the Build settings.

Does this line get printed in the debug window?

Yeah until I got messed up when I was trying to figure out my problem. Now I’ve lost at least one prefab and my audio file so it won’t even start playing.

How do you use the Sourcetree to go back to a previous state?

You may want to access knowledge base for source tree , you want to be mindful how you save the scene files and their hierarchy. Make sure the intended level one has the index of zero

index of zero: you mean in the build settings?

I’m not sure what you mean on saving the scene files and their hierarchy.

Yes in the build settings , and as well switching to WebGL as ben did, if you did both then the problem is in the code. I wish i knew how to revert in source tree but i just make sure i save my desired states so the panic goes away when i do mess up

For the build settings, my levels are showing up in there but am I supposed to click on build right now or later on when we complete the game?

You do not build just yet my friend , after you see your scene order in the tab , just x out and save it should work with the proper code

Ok, that’s what I thought.

Well, I managed to get my audio back so it will play now but my rocket is going too fast to control and just takes off into never never land. I’ve adjusted the thrust in the inspector and can’t seem to get it where I can control it. I even tried adjusting the mass. Right now I have the rcs set at 50 and the main thrust set at 25 and the mass at 0.02.

Hmm , ok with that i might ask , is your prefab updated? if so , then what is the values in Rocket.cs for rcs and main thrust?

You may want to take another visit to the course vlog, ben shows exactly how he uses framerate Independence claus in rocket.cs for thrusters. you want to make sure all of your code is in line as far as variable names too. it can get tricky but if you stick with it and debug even when it bugs you then you will be ok, Good Luck you got this!

Both of those values are 100f

Thanks for your help. I’ll keep adjusting it till I get it right. I was able to control it before I had the issue with my second scene not loading. Trying to fix issues certainly is “buggy.”

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

Privacy & Terms