I need help with making a game over when an object interacts with a wall?
Hi everyone, Im trying to get the game load a scene due to a ball colliding with a wall. I already put a circle collider to the ball and a box collider to the wall but when Im making the script work i got this message in the console:
Assets/Scripts/wall.cs(10,39): error CS0246: The type or namespace name `ball' could not be found. Are you missing an assembly reference?
I really dont know what to do, while the colliders can interact each other I still cannot make the if statement to "reset" the game and start again. I have attached the "Wall collision collider script" to the wall object colored in blue and the ball is red.
I put some pictures of the project below.
Honestly, thank you.
@korpos95 The type or namespace name 'ball' could not be found.
means that it doesn't recognize ball
. I see you have a wall class here (in your screenshot). Do you have a ball class in your project? If no then Unity doesn't recognize ball because there's no such a class/type. You are using the <> syntax, it's expecting you to put a type.
Unity has Scripting Tutorials. They might be helpful if you are new to program$$anonymous$$g.
Try to create a ball class and attach it to your ball object. Usually people like to name classes starting with uppercase, so Wall and Ball, not wall and ball.
Another way is to compare tag. Set your ball object's tag to Ball. Then change your if statement to
if (collision.collider.CompareTag("Ball")) {
Debug.Log("Ball hit!");
}
Your answer
Follow this Question
Related Questions
Sprites are wiggle / shaking while moving the player. 1 Answer
Built game doesn't work as the game preview 0 Answers
Problem with my dash ability, 1 Answer
Competing box colliders? 0 Answers