As the title implies I need help coding this. I’m working on a breakout-style game where xGameobject is a ball that will collide with other gameobjects under a certian label “wall”. What am I doing wrong? there are no errors, but the walls won’t destroy…
using UnityEngine;
using System.Collections;
public class Wall : MonoBehaviour {
private GameObject xGameObject;
void OnCollisionEnter(Collision col)
{
if(col.transform.tag == "Wall")
{
Destroy(xGameObject);
}
}
}
Hmmm… Your script is named “Wall”, so I assume it is attached to the wall objects? If so, then it’s no wonder it doesn’t work since no wall object will ever register a collision with another wall object A good example of a logic error.
What you need to do is put the script on the Ball object instead.
As another tip: Insert Debug.Log lines in your code to print information in your console during runtime; For example, you can use
Debug.Log(gameObject.name + " has registered a collision with " + col.gameObject.name);