@ BPPherv thanks again comes in handy to know.
I’m a bit confused now with the difference between a public function and a public class and when to use what…
Like i said I’m doing this mining thing and then the laboratory where you can do 4 main things: boil, freeze, mix and split
I have 4 objects for that in the scene, in the GUI if have the elements in your inventory together with the amounts. so now you can drag an element from your inventory into 1 of the four objects and it adds it to the loop for your chemical cook .
the cooking is no more then getting the elements names check the amount and the number of electrons, in a for loop. and sending the result to a function that calculates a string that comes out and renders to the GUI atm.
this is all in my cooking script. on my objects i only have a public class like BPPherv showed me above and a public array that keeps the name/amount/nr of electrons of elements in circulation.
so my question is, should i better split up the calculations for the 4 objects and makes public classes or functions in each there own script. As now all these will be sitting in one function that gets run with constantly checking for loop accessing the script of the object with only the array of elements?
this is the for loop i use and the function it calls:
//one of the 4 for loops to get the elements dropped in one of the 4 bottles
if(selected tool=="mix")
{
//var bind:boolean;
Debug.Log(obj.GetComponent(elementsAmount).elements.length);
GUILayout.Label("mixing container");
if(obj.GetComponent(elementsAmount).elements.length>3)
{
scrollPosition=GUILayout.BeginScrollView (scrollPosition);
GUILayout.BeginVertical();
for (var e=0; e<obj.GetComponent(elementsAmount).elements.length; e+=3)
{
for(var a=3+e; a<obj.GetComponent(elementsAmount).elements.length; a+=3)
{
var moleculeE:String=obj.GetComponent(elementsAmount).elements[e];
var moleculeA:String=obj.GetComponent(elementsAmount).elements[a];
var elektronE:int=obj.GetComponent(elementsAmount).elements[e+1];
var elektronA:int=obj.GetComponent(elementsAmount).elements[a+1];
var amtE:int=obj.GetComponent(elementsAmount).elements[e+2];
var amtA:int=obj.GetComponent(elementsAmount).elements[a+2];
setBox(moleculeA,elektronA,amtA,moleculeE,elektronE,amtE);
GUILayout.Box(GUIString);
}
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
}
//example of what the function should do
function setBox(NH:String,eH:int,AH:int,NL:String,eL:int,AL:int)
{
if(NH!=NL (eH+eL)/(AH+AL)==8 || (eH+eL)/(AH+AL)==1)
{
GUIString=AH+""+NH+""+AL+""+NL+""+(eH+eL);
}
if(NH==NL AH==AL eH==eL)
{
GUIString=(AH+AL)+""+NH+""+(eH+eL);
}
}