- Home /
Camera distance
how to calculate distance of object from camera?? ALSO THERE ARE MULTIPLE OBJECTS.Please help me??
Answer by henry96 · Jul 16, 2012 at 06:39 AM
Calculate the distance, using Vector3.Distance might seem a good idea.
For example :
var object : Transform;
Vector3.Distance(object.position, transform.position);
If there are multiple objects, you can use GameObject.FindGameObjectsWithTag
Hope this helps.
thnx for your sincere reply. i already did that. i am trying to solve one of my complex problem that i am stuck with for over a week. $$anonymous$$indly look into my problem " Objects co$$anonymous$$g on other objects" on my profile. I would be highly obliged if you could help me out with that.
By the way, if what you post is not the answer, just post them as comment
I used mesh merger script to combine my meshes which uses tree texture. Also, I used "transparent/diffuse" shader. I dont want alpha as it reduces the performance. Now my question is that when i enter the game mode, some trees draws in front of the tree which are nearer. i am attaching an image.kindly help.
or to be more specific can anyone give me some script so that object queue is rendered according to the camera distance so that objects nearer are drawn later and objects far away draw first.!
I see. The simplest idea I have in $$anonymous$$d is, write a script for the tree itself or camera. But in this case, just focus on the tree. And use the distance script above. Check if the distance between the tree and the camera is more than 5 or 10 or whatever you prefer, then make it visible. If not, invicible.
This case, you need to disable/enabled to things, renderer and collider.
renderer.enabled = false; collider.enabled = false;
Hope this fits your situation.