Setting up Security Camera’s
Now we get to move towards working on the next obstacles in our game. Near the end, we have some security camera’s that we have to sneak by without being detected. As of now, they are just stationary, but let’s make a change to that. To start, let’s create an animation clip, just as we did with our cutscenes earlier, and create a 1 second movement for our camera:
From here, we can go into our animator and make a few adjustments:
What we are doing here is creating a duplicate of the current animation that we created. What we will do is adjust the speed of it to -1, as that will reverse the direction of out animation:
Once we have it the transitions going back and forth between the 2 directions, we can see our camera’s moving back and forth in the game:
Next, we need to build in some sort of detection for the camera’s to enable our game over scenario. This will be a process just like the eyes we did for the guards, but as we already have a cone to work with for our camera’s light, we can just use that as our detector:
Once we attach our script and rigid body to the Cameracone, we can test it out in the game to see if it switches to our cutscene:
With how we have our cutscene built, we currently have it so that our playable character will sit within the cutscene while the actors within the cutscene play out the scenario. What this does is create the illusion that we have 2 separate players. To fix this issue, we will go into our game over cutscene and add in a new activation track and have our actual player reappear at the very last frame:
With this in place, we can test it in the game and see if the player disappears the moment he is detected:
To finish up our camera’s properties, we are going to have it freeze when it touches our player, along with turn it red upon impact to:
For the freeze effect, we need to move our game over cutscene into a coroutine so that we can give the game a slight pause before the game over cut scene goes off. We will also want to attach the animation of the camera to our cone so that we can pull the component in our script and disable it upon trigger. Finally for the colour change, we will want to code in the colour values we want for our object as we will not use a preset colour in the system. To do this, we need to take the value’s of each shade and divide it by the total value it could be:
As the value for the RGBA is from 1–255, we will take whatever value we decide upon and divide it by 255 to give us the values.
Once we have all of that done, we can see if the stopping of the camera that detected us occurs, along with a change in the colour:
Now that we have our camera’s working, we can move towards the next part of this game.