Friday, 25 April 2014

Pick up and Throw Code

For our protagonist character we thought that she would need to be able to pick up the orb and be able to throw it away from her if an alien came near her (our game is about Aliens farming humans on a global scale).

As I am the main coder for our group, I created a new Unity Project - (just in-case I ran in to major problems) I did not want to ruin the main file.



In the above screenshot, I have tried to give an overview of the basic scene that I have created. 
Over on the right hand side you see the three scripts that I have used. The first one is the Object Properties script, which is in C#. This script is attached to the object that you want to pick up. For this script to work, the object needed a collider so that the character controller could be able to pick it up. It also needed a rigid body component added to it as well. 

The next script is another C# script, called Pick up and Throw. This is attached to the character controller which enables it to be able to pick up the object when the player presses the 'f' key on the keyboard, as well as being able to throw the object when the player clicks the left mouse button.

The final script is Javascript (In my first year at University we were given brief tutorials on how Javascript works). This script is called Power Meter. This also goes on the character controller, and this controls the power in which the object is thrown by the character.


Here, below are the screenshots of the Pick up and Throw script, as well as the Object Properties script.

This first screenshot is part of the Pick up and Throw script.



This second screenshot is the last part of the Pick up and throw script.

Now below is the screenshot of the Object properties script.


Hopefully in the not too distant future I will have a video showing how these scripts work within the Unity scene.

No comments:

Post a Comment