我正在Unity上创建2D游戏,您作为玩家可以在一个封闭的空间中移动,炸弹在您上方生成并掉落在屏幕上,您必须避开它们,但是在创建边界时,炸弹会与之碰撞不会继续掉下去,它们只是停留在墙壁上。因此,我需要忽略墙壁与炸弹之间的碰撞,而不是玩家与炸弹之间的碰撞。这是我的代码:
public Transform[] spawnPonts;
public GameObject[] enemyPrefabs;
public float respawnTime = 5f;
private GameObject bomb;
void Start () {
InvokeRepeating("Spawn", 3f, respawnTime);
}
void Spawn() {
bomb = Instantiate(enemyPrefabs[0], spawnPonts[Random.Range(0, spawnPonts.Length)].position, transform.rotation);
}
private void OnCollisionEnter2D(Collision2D col) {
if (col.gameObject.tag == "Wall") {
Physics.IgnoreCollision(bomb, col.transform.gameObject);
}
}
我在遇到错误
private void OnCollisionEnter2D(Collision2D col) {
if (col.gameObject.tag == "Wall") {
Physics.IgnoreCollision(bomb, col.transform.gameObject);
}
}
说“无法将'UnityEngine.GameObject'转换为'UnityEngine.Collider'”