Guest User

Shooting

a guest
Jan 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Threading;
  4.  
  5.  
  6. public class Shooting : MonoBehaviour {
  7.  
  8.     public GameObject bullet; // defining objecst here  
  9.     public GameObject gun;
  10.     public Ppauser pauzer;
  11.     AudioSource shoots;                                  
  12.     public float speed = 30f;
  13.     public float timer  = 0.0f;
  14.     public float maxtimer = 0.5f;
  15.    
  16.  
  17.  
  18.     void Start ()
  19.     {
  20.        
  21.         Cursor.visible = false;
  22.         Cursor.lockState = CursorLockMode.Locked;
  23.         shoots = GetComponent<AudioSource>();
  24.        
  25.     }
  26.  
  27.     void FixedUpdate ()
  28.     {
  29.  
  30.         timer += Time.deltaTime;
  31.        
  32.         if (Input.GetMouseButtonDown(0) && pauzer.paused == false && timer >= maxtimer)
  33.         {
  34.             shoots.Play();
  35.             timer = 0.0f;
  36.             GameObject shooted = Instantiate(bullet, transform.position, transform.rotation) as GameObject;
  37.  
  38.             Rigidbody rbb = shooted.GetComponent<Rigidbody>();
  39.             rbb.AddForce(shooted.transform.forward * speed);
  40.         }
  41.     }
  42.  
  43.  
  44. }
Add Comment
Please, Sign In to add comment