Advertisement
LittleAngel

Untitled

Jul 11th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. var inventory : Array;
  2.  
  3. private var doWindow : boolean = false;
  4. private var clicked : boolean = false;
  5.  
  6. public var emptyTex : Texture;
  7.  
  8. public var inventorySizeX = 4;
  9. public var inventorySizeY = 5;
  10.  
  11. var iconWidthHeight = 32;
  12. var spacing = 4;
  13.  
  14. public var offSet = Vector2( 100, 100 );
  15.  
  16. private var itemImage : Texture2D;
  17.  
  18. ///////////ITEM AUDIO///////////
  19. var soundPotion : AudioClip;
  20.  
  21. ////////////////////////////////
  22.  
  23. public class InventoryItem{
  24.  
  25. var worldObject : GameObject;
  26. var texRepresentation : Texture2D;
  27. var ItemName : String;
  28. var ItemClass : String;
  29. var ItemDescription : String;
  30. var Damage : int;
  31. var Defence : int;
  32. }
  33.  
  34. function Awake(){
  35. inventory = new Array(inventorySizeX);
  36.  
  37. for( var i = 0; i < inventory.length; i ++ ){
  38. inventory[i] = new Array(inventorySizeY);
  39. }
  40. }
  41.  
  42. function OnGUI() {
  43. var texToUse : Texture2D;
  44. var currentInventoryItem : InventoryItem;
  45.  
  46. for( var i = 0; i < inventory.length; i ++ ){
  47.  
  48. for( var k = 0; k < inventory[i].length; k ++ ){
  49. currentInventoryItem = inventory[i][k];
  50.  
  51. if( inventory[i][k] != null ){
  52. texToUse = inventory[i][k].texRepresentation;
  53. _itemName = currentInventoryItem.ItemName;
  54. _itemClass = currentInventoryItem.ItemClass;
  55. _itemDamage = currentInventoryItem.Damage;
  56. _itemDefence = currentInventoryItem.Defence;
  57. }
  58. if (GUI.Button( new Rect(offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse)){
  59. clicked = true;
  60. }
  61.  
  62. if(clicked && _itemClass == "Melee Weapon"){
  63. Debug.Log( _itemName + _itemClass + _itemDamage + _itemDefence);
  64. clicked = false;
  65. }
  66. if(clicked && _itemClass == "Food"){
  67. Debug.Log("Food");
  68. animation.CrossFade("Consume",0.2);
  69. clicked = false;
  70. }
  71. if(clicked && _itemClass == "Potion"){
  72. Debug.Log("Potion");
  73. SendMessage("Potion");
  74. clicked = false;
  75. }
  76. if(clicked && _itemClass == "Helmet"){
  77. Debug.Log("Helmet");
  78. clicked = false;
  79. }
  80. }
  81. }
  82. }
  83.  
  84. function AddItem( item : InventoryItem ){
  85.  
  86. for( var i = 0; i < inventory.length; i ++ )
  87. {
  88.  
  89. for( var k = 0; k < inventory[i].length; k ++ )
  90. {
  91.  
  92. if( inventory[i][k] == null )
  93. {
  94. inventory[i][k] = item;
  95. return;
  96. }
  97. }
  98. }
  99. }
  100.  
  101. function AddItem( worldObject : GameObject, texRep : Texture2D, itemName : String, itemClass : String, ItemDescription : String, damage : int, defence : int){
  102. var newItem = new InventoryItem();
  103.  
  104. newItem.worldObject = worldObject;
  105. newItem.texRepresentation = texRep;
  106. newItem.ItemName = itemName;
  107. newItem.ItemDescription = ItemDescription;
  108. newItem.ItemClass = itemClass;
  109. newItem.Damage = damage;
  110. newItem.Defence = defence;
  111.  
  112. AddItem(newItem);
  113. }
  114.  
  115. function Potion(){
  116. var currentInventoryItem : InventoryItem;
  117.  
  118. for( var i = 0; i < inventory.length; i ++ ){
  119.  
  120. for( var k = 0; k < inventory[i].length; k ++ ){
  121. currentInventoryItem = inventory[i][k];
  122.  
  123. if( inventory[i][k] != null ){
  124. _itemName = currentInventoryItem.ItemName;
  125. _itemClass = currentInventoryItem.ItemClass;
  126. }
  127. }
  128. if(_itemName == "Health Potion"){
  129. player = GameObject.FindGameObjectWithTag("Player").GetComponent("PlayerHP");
  130. if (player.hitPoints >= player.maximumHitPoints)
  131. return;
  132. animation.CrossFade("Consume",0.2);
  133. player.hitPoints += 50;
  134. audio.PlayOneShot(soundPotion);
  135. player.hitPoints = Mathf.Min(player.hitPoints, player.maximumHitPoints);
  136. clicked = false;
  137. }
  138. if(_itemName == "Gravity Potion"){
  139. playerMovement = GameObject.FindGameObjectWithTag("Player").GetComponent("AdvancedMovement");
  140. animation.CrossFade("Consume",0.2);
  141. playerMovement.gravity = 5;
  142. audio.PlayOneShot(soundPotion);
  143. clicked = false;
  144. yield WaitForSeconds(30);
  145. playerMovement.gravity = 15;
  146. }
  147. }
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement