- Home /
Screen go darker when it look at an Object?
Anyone can tall me how can i do when i look at an object the camre screen is darking (soory fo my bad english i m hun :) ) Please tall me anyone I tootally no have any idea !
Answer by aldonaletto · Aug 25, 2012 at 01:09 AM
The easiest way to darken the screen is to place a black texture in front of the camera and control its alpha value - 0 is normal screen, 1 is completely dark.
If you want the darkness to be max when looking directly to the object, and gradually reduce as you look to other direction, use a dot product to calculate the alpha (camera script):
var black: Texture2D; // drag a black texture of any size here var target: Transform; // drag the object here var sensitivity: float = 1; // darkness sensibility to the angle
private var darkness: float = 0;
function Update(){ // find the object direction normalized: var dir = (target.position - transform.position).normalized; // darkness is max when looking directly to the object: darkness = 1 + sensitivity * (Vector3.Dot(dir, transform.forward)-1); }
function OnGUI(){ GUI.color.a = Mathf.Clamp(darkness, 0, 1); // set the black alpha GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), black); }
Your answer
Follow this Question
Related Questions
Object doesn't stick on Camera right Corner?? (Basic Question) 1 Answer
How do you clamp a camera by mobile width? 2 Answers
Instantiate duplicates script in subsequent Objects 2 Answers
How do I rotate an object on one axis to face android touch? 0 Answers
Toggle between scripts with a script? 2 Answers