- Home /
Question by
charliepup03 · May 12, 2020 at 10:29 AM ·
c#scripting problemcollision
Goal Collision for pong game
I'm a noob when it comes to unity and I cant figure out how to get the collision to work for my goals when the ball hits them. I used a debug.log to see if the collision works and named it ("GAME OVER"), but it wont show up. Again I really have no idea what i'm doing, but I'm learning.
CODE FOR BALLCOLLISION
using UnityEngine;
public class BallCollision : MonoBehaviour
{
public Ball movement; // reference to Ball script
public GameManager gameManager;
void OnCollisionEnter (Collision collisionInfo)
{
if (collisionInfo.collider.tag == "Goal")
{
movement.enabled = false;
FindObjectOfType<GameManager>().EndGame();
}
}
}
CODE FOR GAMEMANAGER:
using UnityEngine;
public class GameManager : MonoBehaviour
{
public void EndGame()
{
Debug.Log("GAME OVER!");
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How can i look for collisions of the bulidngs in may array ? how can i use OnTRiggerEnter/exit ? 0 Answers
Hi! How can I use the OnTriggerEnter2D function for the game objects that I instantiate? 3 Answers
How can I have the player be able to kill an enemy by jumping on top of it? 1 Answer
How to keep score and reset score when hitting walls? 1 Answer