- Home /
Why is this script now working?
This is really getting on my nerves. I can't figure out where the problem is! It's supposed to destroy a coin when the player collides with it but it doesn't, the player collides with it and nothing happens (The coin is still there).
#pragma strict
var player : Transform;
function Start (){
}
function Update () {
}
function OnCollisionEnter(collision : Collision)
{
if(collision.transform == player);
{
Destroy(gameObject);
}
}
Answer by lancer · Aug 18, 2013 at 11:31 PM
Try:
#pragma strict
var player : Transform;
function Start (){
}
function Update () {
}
function OnTriggerEnter(collision : Collider){
if(collision.name == "Player"){
Destroy(gameObject);
}
}
Is your coin collider set to Is Trigger?? And is your player called Player in the hierarchy??
No and Yes.
I'll check if it works by setting it to trigger.
Worked more than fine!
Thx guys for answering my stupid questions :3
Your answer

Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
How to make a Character controller destroy an object? 3 Answers
How can I set the order of destruction of game objects? 1 Answer
Can I stop my player from coming to a stop when colliding? 2 Answers
Simple Script Issue 1 Answer