show and hide objects

Hi all,
I have a scene with 9 plane objects .i have created a ball instantiate and i want to place the balls on all those planes.if i place a ball into 1st plane it want to be hide make all other 8 planes are visible…

and when i place it into 2nd plane it also want to be hide with 1st plane and other 7 are visible…

the process are simultaneously upto all planes will be covered.

can any one say the ans???

how can i solve this? need help!!!

So which ever plane the ball collides with the plane becomes invisible?

Attach a collider to the planes and sphere. Add a script to the plane and add the function:

void OnCollisionEnter( Collision coll )
{
      self.meshRenderer.enabled = false;
}

void OnCollisionExit( Collision coll )
{
      self.meshRenderer.enabled = true;
}

Simples.

hi Gavin,
I’m a begineer to unity,

Its showing error as “Unknown Idenitifier : self”,

actually when i click (OnMouseDown()) to the plane the ball will appear center of that plane,

and where i wanna to attach the script you have mentioned above?

Oops. Thats an object C thing. Change self to this. Attach the script to all of the planes.

hmmmmm…now its showing error like this gavin.

‘meshRenderer’ is not a member of ‘planeScript’.

how can i add it as a member?

have i want to declare it as a variable?

i have already attached meshRenderer on inspector pane?

My bad, i thought GameObjects had a MeshRenderer property.

Try:

MeshRenderer pMesh = (MeshRenderer) this.GetComponent( typeof( MeshRenderer) );
pMesh.enabled = false;

I think that will work.

Edit: It does have a property. This should also work:

self.renderer.enabled = true;

the exact script is:

pMesh =this.GetComponent( typeof( MeshRenderer) );
pMesh.enabled = false;

its running with out error … but the object doesn’t get hide…

Do you mean just “renderer”?

nope !
trying to took out mesh renderer property from that game object…thats it.

Add:

Debug.Log(“Collision Enter”);

To that function.

Do all objects have colliders added to them? And does the sphere have a rigidbody attached?

ya i have already attached colliders on my gameobjects. i think that OnCollisionEnter() function is not working which was said by gavin. problem in that only…

function OnCollisionEnter (collisionInfo : Collision) : void
Description
OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

In contrast to OnTriggerEnter, OnCollisionEnter is passed the Collision class and not a Collider. The Collision class contains information about contact points, impact velocity etc. If you don’t use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unneccessary calculations. Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.

From the documents.

Perhaps the ball GameObject has children with renderers, in which case you can try:

var renderers = gameObject.GetComponentsInChildren(Renderer);
    for (var r : Renderer in renderers) {
        r.enabled = !r.enabled;

Thanks for the lines, I can also use this for a game where you can shoot peoples body-armor guns of and have them come back on when the hitpoints are right.