20121109

Weapon Pickup Script (Javascript)


This script allows players to pickup weapons and assign them to their player. I have implemented a simple interface for the level designer so that when they place a generic WeaponPickup prefab down they can choose between all the available weapons which currently is 5. 

Within the script I hard code the weapon stats, to simplify the level designers GUI. Weapon statistics should be consistent within a game so there is no need for them to modify the stats of each weapon pickup they place in a level. One statistic the level designer can adjust is the respawn time of the weapon, this is a vital variable as it could effect the actual flow of a level if a weapon takes X time to respawn.

I have applied three statistics to each type of weapon, these include range, speed and damage. 

The script detects if the collider is first a player (as later in development abilities such as a banana skin collider could trigger the pickup and cause the game to glitch.) and then checks whether the player already has the weapon, if so the script returns and the pickup continues to be active.   

The only issue with the script currently is if a player picks up a a weapon, and then another player joins, the weapon pickup is visible to them (and they can pick it up) but it is invisible to all pre-existing players who were in the game when the weapon was picked up. The way to solve this (which I have done with the Access Key) is to photonView.RPC("FunctionName",PhotonTargets.AllBuffered) - This means, using the buffer, that when a new player joins the game they are sent a stream of what has happened and they enter up-to-date with the current game.