Advertisement
fireflygamedev

crafting script

Oct 30th, 2014
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var MenuSkin : GUISkin;
  4.  
  5. //References
  6. var player : GameObject;
  7. var mainCamera : GameObject;
  8. var arms : GameObject;
  9.  
  10. //Icons
  11. var campfireIcon : Texture;
  12. var BigTentIcon : Texture;
  13. var teepeeIcon : Texture;
  14. var tentIcon : Texture;
  15. var emptyIcon2 : Texture;
  16. var emptyIcon3 : Texture;
  17. var emptyIcon4 : Texture;
  18. var emptyIcon5 : Texture;
  19. var emptyIcon6 : Texture;
  20.  
  21. //Player prefabs
  22. var campFire : GameObject;
  23. var BigTent : GameObject;
  24. var teepee : GameObject;
  25. var tent : GameObject;
  26. var empty2 : GameObject;
  27. var empty3 : GameObject;
  28. var empty4 : GameObject;
  29. var empty5 : GameObject;
  30. var empty6 : GameObject;
  31.  
  32. // scripts
  33.  
  34. private var showGUI : boolean = false;
  35.  
  36. private var invScript : Inventory;
  37.  
  38. function Start()
  39. {
  40.     invScript = GetComponent(Inventory);
  41. }
  42.  
  43. function Update()
  44. {
  45.     if(Input.GetKeyDown("c"))
  46.     {
  47.        
  48.         showGUI = !showGUI;
  49.  
  50.     }
  51.    
  52.     if(showGUI == true)
  53.     {
  54.         Time.timeScale = 0;
  55.         player.GetComponent(FPSInputController).enabled = false;
  56.         player.GetComponent(MouseLook).enabled = false;
  57.         mainCamera.GetComponent(MouseLook).enabled = false;
  58.         arms.GetComponent(PlayerControl).enabled = false;
  59.     }
  60.    
  61.     if(showGUI == false)
  62.     {
  63.         Time.timeScale = 1;
  64.         player.GetComponent(FPSInputController).enabled = true;
  65.         player.GetComponent(MouseLook).enabled = true;
  66.         mainCamera.GetComponent(MouseLook).enabled = true;
  67.         arms.GetComponent(PlayerControl).enabled = true;
  68.  
  69.     }
  70. }
  71.  
  72. function OnGUI()
  73. {
  74.     if(showGUI == true)
  75.     {
  76.  
  77.         GUI.skin = MenuSkin;
  78.             GUI.BeginGroup(new Rect(Screen.width/2-150,Screen.height/2-150,300,300));
  79.                 GUI.Box(Rect(0 , 0, 260, 300),"Crafting System");
  80.  
  81.                 if(GUI.Button(Rect(10, 50, 50, 50), GUIContent (campfireIcon, "Build a campfire")))
  82.                 {
  83.                     if(invScript.wood >= 6 && invScript.stone >= 3)
  84.                     {
  85.                         campFire.SetActive(true);
  86.                         BigTent.SetActive(false);
  87.                         tent.SetActive(false);
  88.                         teepee.SetActive(false);
  89.                         invScript.wood -= 6;
  90.                         invScript.stone -= 3;
  91.                     }
  92.                 }
  93.                
  94.                 if(GUI.Button(Rect(10, 120, 50, 50), GUIContent (BigTentIcon, "Build a Bigger Tent?")))
  95.                 {
  96.                     if(invScript.wood >= 10 && invScript.stone >= 5 && invScript.clay >= 3)
  97.                     {
  98.                         BigTent.SetActive(true);
  99.                         campFire.SetActive(false);
  100.                         teepee.SetActive(false);
  101.                         tent.SetActive(false);
  102.                         invScript.wood -= 10;
  103.                         invScript.stone -= 5;
  104.                     }
  105.                 }
  106.                
  107.                 if(GUI.Button(Rect(10, 190, 50, 50), GUIContent(teepeeIcon, "Build a TeePee!")))
  108.                 {
  109.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  110.                     {
  111.                         teepee.SetActive(true);
  112.                         BigTent.SetActive(false);
  113.                         tent.SetActive(false);
  114.                         campFire.SetActive(false);
  115.                         invScript.wood -= 10;
  116.                         invScript.stone -= 5;
  117.                     }
  118.                 }
  119.                
  120.                 // SECOND COLLUMN
  121.                
  122.                 if(GUI.Button(Rect(100, 50, 50, 50), GUIContent(tentIcon, "Build a tent!")))
  123.                 {
  124.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  125.                     {
  126.                         tent.SetActive(true);
  127.                         teepee.SetActive(false);
  128.                         BigTent.SetActive(false);
  129.                         campFire.SetActive(false);
  130.                         invScript.wood -= 10;
  131.                         invScript.stone -= 5;
  132.                     }
  133.                 }
  134.                
  135.                     if(GUI.Button(Rect(100, 120, 50, 50), GUIContent(emptyIcon2, "This is just a place holder")))
  136.                 {
  137.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  138.                     {
  139.                         empty2.SetActive(true);
  140.                         teepee.SetActive(false);
  141.                         BigTent.SetActive(false);
  142.                         campFire.SetActive(false);
  143.                         invScript.wood -= 10;
  144.                         invScript.stone -= 5;
  145.                     }
  146.                 }
  147.                
  148.                 if(GUI.Button(Rect(100, 190, 50, 50), GUIContent(emptyIcon3, "This is just a place holder")))
  149.                 {
  150.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  151.                     {
  152.                         empty3.SetActive(true);
  153.                         teepee.SetActive(false);
  154.                         BigTent.SetActive(false);
  155.                         campFire.SetActive(false);
  156.                         invScript.wood -= 10;
  157.                         invScript.stone -= 5;
  158.                     }
  159.                 }
  160.                
  161.                 if(GUI.Button(Rect(190, 50, 50, 50), GUIContent(emptyIcon4, "This is just a place holder")))
  162.                 {
  163.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  164.                     {
  165.                         empty4.SetActive(true);
  166.                         teepee.SetActive(false);
  167.                         BigTent.SetActive(false);
  168.                         campFire.SetActive(false);
  169.                         invScript.wood -= 10;
  170.                         invScript.stone -= 5;
  171.                     }
  172.                 }
  173.                
  174.                 if(GUI.Button(Rect(190, 120, 50, 50), GUIContent(emptyIcon5, "This is just a place holder")))
  175.                 {
  176.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  177.                     {
  178.                         empty5.SetActive(true);
  179.                         teepee.SetActive(false);
  180.                         BigTent.SetActive(false);
  181.                         campFire.SetActive(false);
  182.                         invScript.wood -= 10;
  183.                         invScript.stone -= 5;
  184.                     }
  185.                 }
  186.                
  187.                 if(GUI.Button(Rect(190, 190, 50, 50), GUIContent(emptyIcon6, "This is just a place holder")))
  188.                 {
  189.                     if(invScript.wood >= 10 && invScript.stone >= 5)
  190.                     {
  191.                         empty6.SetActive(true);
  192.                         teepee.SetActive(false);
  193.                         BigTent.SetActive(false);
  194.                         campFire.SetActive(false);
  195.                         invScript.wood -= 10;
  196.                         invScript.stone -= 5;
  197.                     }
  198.                 }
  199.                
  200.                
  201.                 GUI.Label (Rect (100, 250, 100, 40), GUI.tooltip);
  202.                 GUI.EndGroup ();
  203.       }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement