Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. #pragma strict
  2.  
  3. var rayLength : int = 10;
  4.  
  5. private var inventory : Inv;
  6.  
  7. private var guiShow : boolean = false;
  8.  
  9. var bush : GameObject;
  10.  
  11. var player : GameObject;
  12. var berr:int;
  13.  
  14. function Start()
  15. {
  16. inventory = GameObject.Find("First Person Controller").GetComponent(Inv);
  17. }
  18.  
  19. function Update()
  20. {
  21. var hit : RaycastHit;
  22. var fwd = transform.TransformDirection(Vector3.forward);
  23.  
  24. if(Physics.Raycast(transform.position, fwd, hit, rayLength))
  25. {
  26. if(hit.collider.gameObject.name == "log")
  27. {
  28. guiShow = true;
  29.  
  30. if(Input.GetKey(KeyCode.E))
  31. {
  32. //inventory.wood++;
  33. Destroy(hit.collider.gameObject);
  34. guiShow = false;
  35. inventory.wood++;
  36. }
  37. }
  38. if(hit.collider.gameObject.tag == "BushFull")
  39. {
  40. guiShow = true;
  41. bush = (hit.collider.gameObject);
  42.  
  43. if(Input.GetKeyDown("e"))
  44. {
  45. bush.GetComponent(BushController).berriesTaken = true;
  46. guiShow = false;
  47. player.GetComponent(Inv).cookedFish += 1;
  48.  
  49. }
  50. }
  51. else
  52. {
  53. guiShow = false;
  54. }
  55. }
  56. }
  57.  
  58.  
  59. function OnGUI()
  60. {
  61. if(guiShow == true)
  62. {
  63. GUI.Box(Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 100, 20), "PICKUP!");
  64. }
  65. }
  66.  
  67. var menuSkin : GUISkin;
  68.  
  69. var wood : int = 0;
  70. var stone : int = 0;
  71. var clay : int = 0;
  72.  
  73. var fish : int = 0;
  74. public var cookedFish : int = 0;
  75.  
  76. var bottle : int = 0;
  77. var bottledWater : int = 0;
  78.  
  79. var bandage : int = 0;
  80.  
  81. var minimumVal : int = 0;
  82.  
  83. private var showGUI : boolean = false;//to switch inventory on or off jo key press krne se hoga
  84.  
  85. private var playerGUI : PlayerGUI;
  86.  
  87. function Start()
  88. {
  89. playerGUI = GameObject.Find("First Person Controller").GetComponent(PlayerGUI);
  90. }
  91.  
  92. function Update()
  93. {
  94. if(wood <= 0)
  95. {
  96. wood = minimumVal;
  97. }
  98.  
  99. if(stone <= 0)
  100. {
  101. stone = minimumVal;
  102. }
  103.  
  104. if(clay <= 0)
  105. {
  106. clay = minimumVal;
  107. }
  108.  
  109. if(fish <= 0)
  110. {
  111. fish = minimumVal;
  112. }
  113.  
  114. if(cookedFish <= 0)
  115. {
  116. cookedFish = minimumVal;
  117. }
  118.  
  119. if(bottle <= 0)
  120. {
  121. bottle = minimumVal;
  122. }
  123.  
  124. if(bottledWater <= 0)
  125. {
  126. bottledWater = minimumVal;
  127. }
  128.  
  129. if(bandage <= 0)
  130. {
  131. bandage = minimumVal;
  132. }
  133.  
  134. if(Input.GetKeyDown("i")) //key 'i' press kro to agr on ha inv to off hjae and vice versa
  135. {
  136. showGUI = !showGUI;
  137. }
  138.  
  139. if(showGUI == true)
  140. {
  141. Time.timeScale = 0; //game pause hjaegi kind of sb kch ruk jaega
  142. GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = false;//first person controls disable
  143. GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = false;//mouse control player k disabled
  144. GameObject.Find("Main Camera").GetComponent(MouseLook).enabled = false;
  145. GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerAnimation).enabled = false;
  146. //GameObject.Find("Main Camera").GetComponent(RayCastCollect).enabled = false;
  147. }
  148.  
  149. if(showGUI == false)
  150. {//agr inv ni khuli hwi to baki jo upr false ki hain unhe wapis true krdo
  151. Time.timeScale = 1;
  152. GameObject.Find("First Person Controller").GetComponent(FPSInputController).enabled = true;
  153. GameObject.Find("First Person Controller").GetComponent(MouseLook).enabled = true;
  154. GameObject.Find("Main Camera").GetComponent(MouseLook).enabled = true;
  155. GameObject.Find("FPSArms_Axe@Idle").GetComponent(PlayerAnimation).enabled = true;
  156. // GameObject.Find("Main Camera").GetComponent(RayCastCollect).enabled = true;
  157. }
  158. }
  159.  
  160. function OnGUI()
  161. {
  162. if(showGUI == true)
  163. {//inv menu ki gui sari bn ri ha idhr
  164. GUI.skin = menuSkin;
  165. GUI.BeginGroup(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
  166. GUI.Box(Rect(0, 0, 300, 300), "Basic Inventory");
  167.  
  168. //Resources collected
  169. GUI.Label(Rect(10, 50, 50, 50), "Wood");
  170. GUI.Box(Rect(60, 50, 20, 20), "" + wood);
  171.  
  172. GUI.Label(Rect(90, 50, 50, 50), "Stone");
  173. GUI.Box(Rect(130, 50, 20, 20), "" + stone);
  174.  
  175. GUI.Label(Rect(170, 50, 50, 50), "Clay");
  176. GUI.Box(Rect(200, 50, 20, 20), "" + clay);
  177.  
  178.  
  179. //Empty holders
  180. GUI.Label(Rect(10, 130, 50, 50), "Fish");
  181. GUI.Box(Rect(60, 130, 20, 20), "" + fish);
  182.  
  183. GUI.Label(Rect(10, 150, 50, 50), "Bottle");
  184. GUI.Box(Rect(60, 150, 20, 20), "" + bottle);
  185.  
  186. //Edible items
  187. GUI.Label(Rect(10, 190, 50, 50), "CFish");//label
  188. GUI.Box(Rect(60, 190, 20, 20), "" + cookedFish);//text box type thingy
  189. if(GUI.Button(Rect(100, 190, 100, 20), "Eat Fish"))//button bn ra ha
  190. {
  191. if(cookedFish >= 1)
  192. {
  193. cookedFish--;
  194. Eat();
  195. }
  196. }
  197.  
  198. GUI.Label(Rect(10, 210, 50, 50), "BWater");
  199. GUI.Box(Rect(60, 210, 20, 20), "" + bottledWater);
  200. if(GUI.Button(Rect(100, 210, 100, 20), "Drink Water"))
  201. {
  202. if(bottledWater >= 1)
  203. {
  204. bottledWater--;
  205. Drink();
  206. }
  207. }
  208.  
  209. GUI.Label(Rect(10, 240, 50, 50), "Heal");
  210. GUI.Box(Rect(60, 240, 20, 20), "" + bandage);
  211. if(GUI.Button(Rect(100, 240, 100, 20), "Use Bandage"))
  212. {
  213. if(bandage >= 1)
  214. {
  215. bandage--;
  216. Heal();
  217. }
  218. }
  219. GUI.EndGroup();
  220. }
  221. }
  222.  
  223. function Eat()
  224. {
  225. playerGUI.hungerBarDisplay += 0.1;
  226. }
  227.  
  228. function Drink()
  229. {
  230. playerGUI.thirstBarDisplay += 0.1;
  231. }
  232.  
  233. function Heal()
  234. {
  235. playerGUI.healthBarDisplay += 0.1;
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement