I have a cube and an sphere. I want to disappear the sphere when I click the cube and vice versa.
I am trying to use this function.
void OnMouseDown ( ) {
gameObject.active = false;
}
I have a cube and an sphere. I want to disappear the sphere when I click the cube and vice versa.
I am trying to use this function.
void OnMouseDown ( ) {
gameObject.active = false;
}
Put this script onto your gameobjects, and in the inspector, for each gameobject drag the other one you want to destroy into the OtherObject field.
var OtherObject : GameObject;
function Update()
{
var ray = Camera.main.camera.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Input.GetMouseButton(0))
{
if (Physics.Raycast (ray, hit, Mathf.Infinity))
{
if(hit.collider.gameObject == gameObject)
{
OtherObject.renderer.enabled = false;
}
}
}
}