Well, im learning programming so i have this question. Lets assume that i have two scripts.
one class with “public int money”. Then i instatiate that class
“player.money = 0;” (poor example)
how do i acess this value and increment or decrement this value of this object from another script ?
Sorry for the bad english, isnt my native language.
In the hope that someone onde day will have that question here go the answer.
The class
public class ClassExample{
public int healt
}
The instance of the class
public class Instance{
public ClassExample instanceExample;
void start()
{
instanceExample = new Class;
instanceExample.health=10
}
}
The access to that object.
public class AcessToTheObject{
void start(){
GameObject ThatHoldsTheScript = GameObject.Find("Object");
//Object = the GameObject who has the script you wanna access
Instance AcessVariable = DrugsScript.GetComponent<Instance>();
// Instance = is the component of that object that we wanna access
//in that case the script name "Instance"
AcessVariable.instanceExample.health ++;
}
}