Since our game environment is set in a post apocalyptic environment, we figured a useful game mechanic to have to be a torch seeing as electricity and light would be quite scarce meaning there would be a lot of dark areas, which can be an interesting game mechanic depending on the genre of game. This is seen a lot in horror games.
I approached this by creating a spot light and attaching it to the first person controller at an angle, as shown above.
Then I attached a flashlight script to the spot light.
I wanted the script to work like this:
Get right click input > toggle spot light on/off
By using this script I was able to do this successfully:
var FlashLightOn : boolean = false;
function Update()
{ // Right click = toggle flashlight
if(Input.GetButtonUp("Fire2"))
{
if(FlashLightOn==true)
{
GameObject.Find("FlashlightLight").light.enabled=true;
FlashLightOn=false;
}
else
{
GameObject.Find("FlashlightLight").light.enabled=false;
FlashLightOn=true;
}
}
}
Final result:
Since the game is set on the rooftop people are bound to fall off at some point if there aren’t any barriers like railing or fences set up to prevent this. This is why I made this simple respawn code.
public var deathHeight : float = -5;
public var lives : int = 3;
function spawn()
{
if(transform.position.y <= deathHeight);
{
transform.position = Vector3(4, 1, 0);//change in full game to new respawn point
}
}
This code is attached to the player and states, ‘If the player’s Y-value (number determining vertical position) goes below a certain number, it will transport the player back to the original position at the Vector3 values.
I kept the lives variable in just in case we decide to add the concept of lives to our final rooftop scene.



