- Home /
Question by
aaronmhargrove · May 11, 2016 at 06:18 AM ·
collisionplayercharacterchildrenchild object
Collision Won't Work
I am trying to spawn child objects and have them kill the player when they collide. I used the function from the unity website and it still will not work. Any ideas why?
using UnityEngine;
using System.Collections;
using System;
public class Player : MonoBehaviour
{
public GameObject player;
public GameObject astroid;
public int fallBoundary = -10;
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "astroid")
{
GameObject.Destroy(player);
}
}
}
Comment
Okay so the problem was I forgot to set the tag. Now it is killing the player, BUT it is killing it when there are no asteroids anywhere near it.... so now there is that... ideas?
$$anonymous$$ake your colliders smaller.
Your answer
Follow this Question
Related Questions
Flying collision 0 Answers
Destroy character when collision with enemy 3 Answers
No Collision 3 Answers
Why can't my character jump 2 Answers
How to detect a collision between the character and the bottom of a cube? 1 Answer