Hi How to detect how for is the camera from object? I woudl like to make the object transparent if the camera will get close to in and show it back when the camera wil be further away. Cheers, Lucas
http://unity3d.com/support/documentation/ScriptReference/Vector3.Distance.html Lucas, just use Vector3.Distance Here's a little example from the documentation Code (csharp): var other : Transform; if (other) { var dist = Vector3.Distance(other.position, transform.position); print ("Distance to other: " + dist); }
Sorry for my noob`ish question but could You better explain it to me how to combine this code with my camera/object (in this case a poly object from Maya - pCube1)? I would be very gratful i tried whole day to make it but no luck. my knowledge in programming is... very poor I am an 3d artis cheers
There's a nice trick you can use here. Get the object's heading vector:- Code (csharp): var heading: Vector3 = target.position - camera.transform.position; ...and then get the dot product of this with the camera's forward vector:- Code (csharp): var distance: float = Vector3.Dot(heading, camera.transform.forward; The advantage is that this gives you the distance inward from the plane of the "screen", and it is also a bit more efficient in a frame update.