Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma strict
- /*
- * --Gun_Controller.js
- * @author: Paul Scharnofske
- * @version: 1.0.0
- *
- * This Script have to be bound to the Spawnpostion were the
- * Bullet should spawn. It have to have the right rotation because
- * the bullet takes over the same rotation and position of the
- * spawnpostion.
- */
- // Reference to bullet Object.
- var bullet : GameObject;
- // Sets the maximal Timeout for weapon, default is 25.
- var maxWeaponTimeout : int = 25;
- // The Timeout (counts down).
- var weaponTimeout = 0;
- // for halfautomatic weapons "1" and for fullautomatic weapons set to "0".
- var singleshoot : int = 1;
- // List with all bullets
- var bulletList = ArrayList();
- // Startfunktion executed if the objekt is created.
- function Start () {
- // Resets the Timeout (only because of error avoiding).
- weaponTimeout = 0;
- }
- // Updatefunktion executed every new Frame.
- function Update () {
- //if weapon ready to shoot (Timeout = 0).
- if (weaponTimeout == 0) {
- // if it's an automatic gun.
- if (singleshoot == 0) {
- // if Mouse Button is pressed down.
- if (Input.GetMouseButton(0)) {
- // creates the Bullet (it automaticly goes to spawnposition).
- fire();
- weaponTimeout = maxWeaponTimeout;
- }
- // if it isn't a automatic gun
- } else {
- // if this Frame the Button gets pressed down.
- if (Input.GetMouseButtonDown(0)) {
- // creates the Bullet (it automaticly goes to spawnposition).
- Instantiate(bullet);
- // sets the WeaponTimeout to maximum.
- weaponTimeout = maxWeaponTimeout;
- }
- }
- // if the weaponTimeout isn't 0
- } else {
- // counts weaponTimeout 1 down
- weaponTimeout--;
- // if weaponTimeout is negative
- if (weaponTimeout <= -1) {
- // Throws Exception
- Debug.Log("weaponTimeout is negative");
- // Ends the application
- Application.Quit();
- }
- }
- }
- // This funktion fires the bullet and sets it's roation, scale and position.
- function fire()
- {
- // creates a reference to bullet
- var b = Instantiate(bullet);
- // sets position of bullet to spawnposition
- b.transform.position.x = transform.position.x;
- b.transform.position.y = transform.position.y;
- b.transform.position.z = transform.position.z;
- // sets rotation of bullet to spawnposition
- b.transform.rotation.x = transform.rotation.x;
- b.transform.rotation.y = transform.rotation.y;
- b.transform.rotation.z = transform.rotation.z;
- // adds bullet to bulletList
- bulletList.Add(b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement