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).
- private var weaponTimeout : int;
- // for halfautomatic weapons "1" and for fullautomatic weapons set to "0".
- var singleshoot : int = 1;
- // 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()
- {
- var clone : GameObject;
- clone = Instantiate(bullet, transform.position, transform.rotation);
- clone.transform.position = transform.position;
- clone.transform.rotation = transform.rotation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement