I found a solution to my problem, but it didn't work!

once again, here is my code:

using UnityEngine;
using UnityEngine.SceneManagement;

public class CollisionHandler : MonoBehaviour
{
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case “Friendly”:
Debug.Log(“This thing is friendly”);
break;
case “Finish”:
Debug.Log(“Congrats, yo, you finished!”);
break;
case “Fuel”:
Debug.Log(“You picked up fuel”);
break;
default:
ReloadLevel();
break;
}
}

void ReloadLevel()
{
    int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
    SceneManager.LoadScene(currentSceneIndex);
}

}

I copied the code exactly, and I’m using version 2020.3f.7 BTW

1 Like

Can you describe the details of what is going wrong with your game?

@b4t54ndw1ch This is the same post as this one that I was trying to solve where the Debug.Log wasn’t ‘working’. I don’t know why that just stopped

1 Like

Ahh, I think I remember that one being a little vague. I read your responses to that topic. I think the only thing he didn’t mention trying was checking the tags, if I remember correctly.

My debug.logs are workin now, but I found a solution, and I don’t know how it works

OnCollisionEnter(// what do I put in here for this? ----->); (Collision other)

and my tags, with this solution, should work…

The OnCollisionEnter looks like this

private void OnCollisionEnter(Collision collision)
{
    // Your collision code goes here
}

Not everyone is aware of this, but did you know that you can look at Rick’s code here?:

The changes made in each video are posted below the viewport along with the resources.

Learning how to do a code review is probably your best, number 1 troubleshooting tool. It will really save you a lot of time while waiting for a response to your questions.

I’m not trying to be sarcastic at all. It’s something that we all have to learn, but code reviews are something you signed up for when you made the decision to be a programmer.

Here is how you read it…the red lines of code have been deleted since the last commit. The green lines of code have been added to this commit. You’ll notice that the code skips from line 4 to line 16.

Click on the … to expand the lines of code that have been hidden and you’ll be able to see the entire OnCollisionEnter() method, like meow:

Then you can compare your code to what Rick did in his code.

21DaysLater

This will save you a lot of time when your code has an error.

I hope this helps.

1 Like

Privacy & Terms