Thursday, 28 August 2014

Shooting and Highscore (week #8)

This week was definately the most intense week I've faced during my studies as the pressure was building to finish my first person shooter. The 2 main things I added to my game were Raycast Shooting and a High score. At first I found it extremely difficult to understand Raycast Shooting as it is very different from anything I have encountered  during my studies but now it is quite simple.
I set it up by making an if statement to say when the left mouse button is clicked create a ray from the main camera transform position in a forward direction, if the ray hits a gameobject it instantiates a debris Prefab at the hitpoint. if the ray hits an object collider carrying the enemy script it accesses the recieve damage function from the enemy script.
In order to add a high score to my game I had to use System.IO to save and read .txt files. if the scorecount from my scorecontroller file is greater than the value saved on my score.txt file it becomes the new value for the score.txt file. The high score value is always displayed in a GUI.box by writing score.txt to a string as a high score variable.

My tutor Mike assisted me with all my work this week so unfortunately I am unable to provide any links to good tutorials but it is worth checking out the physics.raycast section of the Unity Scripting Api linked here : http://docs.unity3d.com/ScriptReference/Physics.Raycast.html

No comments:

Post a Comment