I am continuing my previous question( link ). Now its working as per this demo.

and the coding written to set cutoff is here :

function Update () {

    renderer.material.SetFloat("_Cutoff", Mathf.InverseLerp(0, Screen.width, Input.mousePosition.x)); 


But i want to set cutoff value , depending up on distance between two object.

one object position will be static. and i am moving another object and if my object gets far distance then cutoff should be 0. and if the object gets closer then depending up on the distance between these two object , i want to set cutoff value.

so how do i set cutoff value?

Please help me guys?

Thanks in advance for your support and help in advance.

  • \$\begingroup\$ So you problem is to find the distance between two objects in real-time? \$\endgroup\$
    – Korchkidu
    Dec 7, 2013 at 7:03

1 Answer 1


Just compute the length of the distance vector between the moving object and the static object using this code:

// Distance: length of vector (static - moving).
float distance = Vector3.Distance (staticObject.transform.position, movingObject.transform.position);

Pass the float to your material and use it in your shader.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .