In my seen I have Terrine, First person controller and one cube with rigidbody. I want to learn that how can i hide or destroy cube when First person controller collide with cube. Thankyou
JS Version.
var Cube : Transform;
function OnControllerColliderHit (hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "cube")Destroy(Cube);
}
You add this script ot the first person controller.
Here is a c# script that I used to trigger a particle system effect and remove the object from the scene. With a little bit of tweaking you can make it so that it doesn't trigger the particle effect and just vanishes. Than again you might want it to go boom. Your choice. (If you do want it to explode there is a nice explosion particle effect in the standard asset/particle section.)
using UnityEngine;
using System.Collections;
public class OnCollideExplode : MonoBehaviour
{
// A grenade
// - instantiates a explosion prefab when hitting a surface
// - then destroys itself
public GameObject explosionPrefab;
public float explodeSecs = -1;
void Awake()
{
if(explodeSecs > -1) Invoke ("DestroyNow", explodeSecs);
}
void OnCollisionEnter( Collision collision )
{
// Rotate the object so that the y-axis faces along the normal of the surface
ContactPoint contact = collision.contacts[0];
Quaternion rot = Quaternion.FromToRotation(Vector3.up, contact.normal);
Vector3 pos = contact.point;
Instantiate(explosionPrefab, pos, rot);
// Destroy the projectile
Destroy (gameObject);
}
void DestroyNow()
{
Instantiate(explosionPrefab, transform.position, transform.rotation);
Destroy (gameObject);
}
}