- Home /
Make the flashlight follow the mouse.
Here is a flashlight script :
var flashlightOn : boolean = false;
function Update () {
//Checks if the boolean is true or false.
if(flashlightOn == true){
light.intensity = 1;//If the boolean is true, then it sets the intensity to what ever you want.
} else {
if(flashlightOn == false){
light.intensity = 0;//If the boolean is false, then it sets the intensity to zero.
}
}
//Checks if the F key is down and whether the boolean is on or off.
if(Input.GetKeyDown(KeyCode.F) && flashlightOn == false){
flashlightOn = true; //If the f key is down and the boolean is false, it sets the boolean to true.
} else {
if(Input.GetKeyDown(KeyCode.F) && flashlightOn == true) {
flashlightOn = false;//If the f key is down and the boolean is true, it sets the boolean to false.
}
}
}
How can I make it follow my mouse ?
//Checks if the boolean is true or false.
This is an epic comment :)
lol this is a copy-pasta'd script from here: http://forum.unity3d.com/threads/31926-Flashlight
Answer by Blasfemmy · Dec 31, 2012 at 06:05 PM
First, attach this script to a spotlight. Then make this spotlight a child of your main camera. Simply adjust the spotlight so that it looks as if it is being emitted by an unseen flash light.
If you have a 3D model of a flashlight, attach the spotlight (with the script attached) to this flashlight game object, then attach the flashlight game object to the main camera.
If you move the model/ spotlight around, you can position it so that it looks like it is being emitted from a first person view of a(n) (un)seen flashlight.
Your answer
Follow this Question
Related Questions
How to convert the MouseLook(Script) to a java script. 1 Answer
Mouse Aiming Follow Wrong Direction - Help 2 Answers
Attach an object to the mouse cursor? 0 Answers
Rotating a Sphere with the mouse? 1 Answer
Click to destroy object 2 Answers