- Home /
The question is answered, right answer was accepted
Please help in optimizing a project!
I'm making a game, but it's really laggy. I think, the problem is in some high-poly models. Could anybody help me with a script I will attach to them, that will turn off their renderer while they are far enough? I'm not strong in programming, but it should be something like player, mytransform, maxdistance and distance variables, if distance between the player and the object is more than maxdistance, turn off the renderer, else turn on. Thanks in advance!
var distance = Vector3.Distance(object1.transform.position, object2.transform.position);
then make a code that if distance < a specific distance renderer.enabled = true; otherwise renderer.enabled = false;
this should work, but i didnt try it out
Answer by Ambro · Dec 04, 2013 at 02:23 PM
If you have Unity Pro, you should use LODGroup Component to cull your high-poly models when they are far away : http://docs.unity3d.com/Documentation/Manual/LevelOfDetail.html
Just attach this component to your object, keep only one level of detail and assign your renderer to it.
If you don't have Unity Pro, the solution by Manco Capac seems right to me. I would personaly use a coroutines to do some verifications over the time.
That was just god damn exactly what I needed! Thank you EXTRE$$anonymous$$ELY much!
Follow this Question
Related Questions
Too much assets for mobile game 0 Answers
How Do I Not Render Objects That My Player Doesn't See 1 Answer
What do I add to the LOD Renderer in MonoBehaviour? 2 Answers
Is it possible to hide certain particles (disable rendering) while still calculating its motion? 2 Answers
Does it affects the game performance if there are multiple meshes in some parts? 1 Answer