Thursday 1 November 2012

Games Encounters 2 - Unity Scripting

 
I've made quite a few additions to my unity Project since the first update. We had mainly been focusing on scripting to add features to my world.
 

The very first feature I added was a campfire. Using a stock model, I placed it in the world, and then added particle effects to the model to create fire and smoke. These were easy to create as they were just textures with an alpha channel.

The next task was to add a scrip to turn the fire on via collisions. My first part of the script was a function to pick up a set of matches from the world, once the matches were picked up and 'added' to my character, I could then walk to the fire and light it. The script checked whether I had any matches on me, and if I did it would add the fire particle effect.


To add some challenge to game world, I placed the matches inside a wooden hut that was locked. It could only be opened by obtaining four batteries, in the same manner that we obtained the matches. Once the batteries were collected the door would open when colliding with it. I also added a GUI to the game showing how many batteries had been collected.


I later replaced the hut with a model of a crashed helicopter that I made in 3ds max, that would open in the same way.


For another challenge, I imported a target range, and removed one of the batteries from the world. The aim was to 'win' the last battery by beating the target game. The targets were animated, and would stand up in their idle state, and would fall down when a projectile collides with them.


I then had to make a launcher script, that would fire coconuts when pressing the left mouse button. The coconuts are merely textured spheres with a collider on them. When the spheres collide with the target it becomes knocked down.


When all targets are down, a script spawns the final battery.

I've learnt alot from these past few weeks of working with unity, I hope to go back and polish some of these elements, aka texturing the helicopter, etc. But where it stands I think I've got a solid framework to begin expanding on certain game features (shooting, expoloration, etc)

No comments:

Post a Comment