i am trying to hide objects by settings its renderer to false, but it seems that it is still there in the scene since OnMouseOver doestn work on the object behind the one that i just hid… is there a way to really hide the object? any ideas?
Setting the Render to false doesnt change the collider thats why mouseover still picks up the hidden gameobject you need to turn off the collider or add it to the ignore raycast layer when your trying to hide a gameobject.
Or do a simple thing like save the objects vector3 then move it 100meters below your terrain and when you want it back move it to the saved vector3, effectively “hideing” it in a roundabout way.
You can also deactivate the object from another script attached to another object. Simply get a reference to the object you want to hide from the other script.
otherObject:GameObject;
function Update(){
if(your condition here){
otherObject.active = false;
}else if(your other condition){
otherObject.active = true;
}
}
i have this function for hiding objects
function HideCurrentObject(){
//MAKE CURRENT SELECTION UNRENDERABLE
if(cam.currentTarget.renderer.enabled){
cam.currentTarget.renderer.enabled=false;
//THIS DOESN'T WORK, IT WOULD BE NICE IF IT DID
cam.currentTarget.collider.enabled=false;
} else {
cam.currentTarget.renderer.enabled=true;
}
}
so, i would like to go with making GameObject not active. i have cam.curretTarget variable as Transform. i can get a name like this cam.currentTarget.name and use it to find GameObject
like this: GameObject.Find(cam.currentTarget.name).active=false
but how later to activate it again? is it possible to do it this way?
or it is better to temporarly put it in the ignore raycast layer…how to do that?
I’m not an expert by any means but maybe record the object’s properties in an object variable, then destroy it and re instantiate it OnMouseOver and OnMouseOut?
var hideObj: Object = {};
hideObj.property1 = destroyedObject.property;
idk just an idea.
Another thing I read is you could change the texture to a transparent texture? (a blank PNG)
Hope this helps
Lemme know if it does!
it seems that easiest way of doing this is putting object that need to be hidden to ignore raycast layer, and previously setting its renderer to false.
like this:
Objects[k].renderer.enabled=false;
//ADD TO IGNORE RAYCAST LAYER
Objects[k].layer=2;
Objects are GO found by GameObject.FindObjectsWithTag
Ahhh okay i see ![]()
What’s the number ? (layer=2) is layer “2” just some arbitrary number or is layer “2” an actual layer for something specific?
ignore raycast layer is by default number 2
default one is 0