Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ProjectileShooter : MonoBehaviour{
  5.  
  6. public GameObject prefab;
  7. public float timeBetweenShots;
  8. public bool CarryingWeapon = false;
  9.  
  10. private float timeShots;
  11.  
  12. void Start () {
  13. prefab = Resources.Load("projectile") as GameObject;
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18. timeShots += Time.deltaTime;
  19. if (Input.GetMouseButtonDown(0) && timeShots >= timeBetweenShots)
  20. CarryingWeapon = true;
  21. {
  22. timeShots = 0;
  23. GameObject projectile = Instantiate(prefab) as GameObject;
  24. projectile.transform.position=transform.position+Camera.main.transform.forward * 2;
  25. Rigidbody rb = projectile.GetComponent<Rigidbody>();
  26. rb.velocity=Camera.main.transform.forward * 40;
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement