I think the problem comes from the collision detection. Because when I try to iterate all of them and make their renderer’s false. It works. But when I use gameObject.renderer.enabled = false. They will not work.
Basically, setting individual object’s renderer to false will not work.
Any suggestion on how to solve the detection problem?
Don’t rely on the auto-generated name. For example if your cloned object hold a reference to his own prefab, the reference will be changed when he’s instantiated. If the clone create another instance it will clone itself instead of the original prefab. The name will be “Air Bubble(clone)(clone)” in that case.
You can either set a fix name when you instantiate the objects, or use a tag name instead of the object name.
Another problem could be that if your object have sub objects also with colliders, you can collide with them and you will get the name of this subobject instead.
To check what the problem is you can temporarily put a Debug.Log("Collided with :" + collision.gameObject.name); in your OnCollisionEnter function. It will print the name of the object you just collided with.
one problem i believe your having here is that your using air bubble(clone) this has caused me problems myself but you can fix this by using tags you could use
airbubble = GameObject.FindGameObjectWithTag(“yourtag”);
and then after doing that in your OnCollisionEnter(collision : Collision)
change that to OnTriggerEnter
so then it should look like this:
function OnCollisionEnter(collision : Collision)
{
if(collision.renderer.name == "Air Bubble")
{
collision.renderer.enabled = false;
}
}
I use c#, but this looks right to me.
track.renderer.enabled=false; //didn't work
//I had to use:
track.renderer.active=false; //this worked
I’ve been trying unity for a couple months now, but I’m getting tired of it. I’m hammering on just because they deal with the low level 3D-hardware startup.