- Home /
Set alpha cutoff value Unity3d
Hello everyone;
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.
$$anonymous$$y objects are in 2d scene. so depending up on x-y axis value i want to set cutoff.
Answer by hirenkacha · Dec 07, 2013 at 07:49 AM
You can use
ratio = 1 - (currentDistance/maximumDistance);
transform.renderer.material.color.a = Mathf.Lerp(0,1,ratio);
And distance you can get from the distance formula simply.
Your answer
Follow this Question
Related Questions
Set Alpha cutoff Unity3d 1 Answer
How to Make a Character Flicker? 1 Answer
A node in a childnode? 1 Answer
Editing the alpha of one GUItext edits the alpha of them all 1 Answer