x


ON hit remove

I have a cube, and when a Sphere hits it I want it to get removed, but it isn't working! I've tried it in C# and Java, but neither will work! Here is my java version:

function OnTriggerEnter(other : Collider){

Destroy(gameObject);

}

and here is my C# version:

using UnityEngine;

using System.Collections;

public class Cube Die : MonoBehaviour {

void OnTriggerEnter () {
    Destroy(gameObject);   
}

}

more ▼

asked Jul 22 '11 at 01:14 AM

Lord Moon gravatar image

Lord Moon
1 4 4 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I've tested the javascript code and it worked fine. Have you set Is Trigger in the cube collider? Have you attached this script to the cube object? If so, the cube should disappear when some rigidbody or character controller collides with it. One more question: is the sphere a rigidbody or character controller? If it is a character controller, it will not be detected if moved with Translate - only CharacterController's Move or SimpleMove ensures it will be detected.

more ▼

answered Jul 22 '11 at 02:05 AM

aldonaletto gravatar image

aldonaletto
41.2k 16 42 195

I forgot Is Trigger! Thank you ;)

Jul 22 '11 at 02:13 AM Lord Moon
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4139
x3443
x764
x91

asked: Jul 22 '11 at 01:14 AM

Seen: 1068 times

Last Updated: Jul 23 '11 at 02:51 AM