hey I’m trying for days to make a mining system with feedback in my GUI.
but i keep getting stuck in tracking the amount of mined Ore.
since I’m a wannabe coder I’m starting to wonder if i can do math or have a changing float in an array at one index? every thing is seem to try is resulting in an array getting stuffed with every step of my climbing number as a new object in the array or stays at 00…
i’ll post my scripts here but i don’t wanna scare people away with the amount to read for this fairly simple question ![]()
mining script;
#pragma strict
var oreAmount:float;
var miningSpeed:float;
var mined:float;
var minedOre:float;
var currentOre:float;
var type:String;
private var addType=false;
private var mining=false;
private var newType=false;
var mySkin:GUISkin;
var player:GameObject;
var inventoryScript:inventory;
function Start ()
{
player=GameObject.FindGameObjectWithTag("Player");
inventoryScript=player.GetComponent(inventory);
}
function OnMouseEnter ()
{
if(oreAmount>0)gameObject.renderer.material.SetColor("_Emission", Color.white);
}
function OnMouseExit ()
{
if(oreAmount>0)gameObject.renderer.material.SetColor("_Emission", Color.black);
}
function OnCollisionEnter()
{
type=tag;
mining=true;
addType=true;
}
function OnCollisionExit()
{
mining=false;
trackAmount=false;
}
function OnGUI ()
{
GUI.skin=mySkin;
if(mining oreAmount>0)
{
addToInventory();
var screenPos : Vector3 = Camera.main.WorldToScreenPoint (transform.position);
GUI.Box (Rect (screenPos.x-5, screenPos.y-15, 65, 20), oreAmount.ToString());
}
}
function addToInventory()
{
oreAmount -=mined;
minedOre +=mined;
if(inventoryScript.types.length==0)
{
newType=true;
}
inventoryScript.totalOre=(currentOre+minedOre).ToString("#00");
for (var i=0;i< inventoryScript.types.length;i++)
{
if (inventoryScript.types[i]==type)
{
print("same");
currentOre=inventoryScript.typeAmount[i];
return;
}
if (inventoryScript.types[i]!=type)
{
newType=true;
}
}
if (newType)
{
print("been in newType");
inventoryScript.types.Add(type);
inventoryScript.typeAmount.Add(minedOre);
inventoryScript.amounts.Add(inventoryScript.totalOre);
newType=false;
}
}
function Update ()
{
print(inventoryScript.typeAmount.length);
mined=Time.deltaTime*miningSpeed;
if(oreAmount==0)
{
mining=false;
trackAmount=false;
}
}
inventory script;
var totalOre:String;
public var types= new Array();
public var typeAmount= new Array();
public var amounts= new Array();
var windowRect: Rect;
private var inventoryWinHeight: int;
private var inventoryWinWidth: int;
private var oreTypeWinWidth:int;
private var DisInventory=false;
function InventoryWindow ()
{
GUILayout.BeginArea(Rect (10,20,50,windowRect.height-50));
for (var name:String in types)
{
GUILayout.TextArea(name);
}
GUILayout.EndArea();
GUILayout.BeginArea(Rect (60,20,30,windowRect.height-50));
for(var amountNR in amounts)
{
GUILayout.TextArea(amountNR);
}
GUILayout.EndArea();
GUILayout.Space(windowRect.height-50);
if (GUILayout.Button("close Inventory"))DisInventory=false;
}
function OnGUI ()
{
if(!DisInventory)
{
if(GUI.Button(Rect(Screen.width-90, Screen.height -35, 75, 20), "Inventory"))DisInventory=true;
}
if(DisInventory)
{
inventoryWinWidth = Screen.width/2;
inventoryWinHeight = Screen.height/2;
oreTypeWinWidth = inventoryWinWidth/6;
windowRect= new Rect ((Screen.width/2)-(inventoryWinWidth/2),(Screen.height/2)-(inventoryWinHeight/2),inventoryWinWidth,inventoryWinHeight);
windowRect=GUILayout.Window (0, windowRect, InventoryWindow, "Inventory");
}
print(amounts);
}