Advertisement
Guest User

Untitled

a guest
May 1st, 2016
89
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4.  
  5. public class PlayerGuns : MonoBehaviour
  6. {
  7. public int[] guns;
  8.  
  9. public float numberofguns;
  10.  
  11. public bool collidedwithcolt;
  12.  
  13. public GameObject player;
  14. public GameObject hand;
  15. public GameObject dropit;
  16. public GameObject fakecoltprefab;
  17. public GameObject coltprefab;
  18.  
  19.  
  20. void Start ()
  21. {
  22. player = GameObject.Find("Player");
  23. }
  24.  
  25. //if you collide guns, if you wanna create new ones just copy and paste with different tag
  26. void OnTriggerEnter(Collider other)
  27. {
  28. if(other.gameObject.tag == "Colt")
  29. {
  30. collidedwithcolt = true;
  31. }
  32. else
  33. {
  34. collidedwithcolt = false;
  35. }
  36. }
  37. void Update ()
  38. {
  39. //if you pickup a gun
  40. if (guns[0] == 0 && (Input.GetKey(KeyCode.E)) && collidedwithcolt == true)
  41. {
  42. GameObject fakecolt = Instantiate(fakecoltprefab) as GameObject;
  43. fakecolt.transform.parent = hand.transform;
  44. guns[0] = 1;
  45.  
  46. }
  47. //drop a gun
  48. if (guns[0] == 1 && (Input.GetKey(KeyCode.Q)))
  49. {
  50. guns[0] = 0;
  51. GameObject colt = Instantiate(coltprefab) as GameObject;
  52. colt.transform.position = dropit.transform.position;
  53.  
  54. }
  55.  
  56. //set number of gun
  57. if (Input.GetKey(KeyCode.Alpha1))
  58. {
  59. numberofguns = 1;
  60. }
  61. if (Input.GetKey(KeyCode.Alpha2))
  62. {
  63. numberofguns = 2;
  64. }
  65. if (Input.GetKey(KeyCode.Alpha3))
  66. {
  67. numberofguns = 3;
  68. }
  69. }
  70.  
  71. }
Advertisement
RAW Paste Data Copied
Advertisement