I am making a FPS and in my fps i have these variables
public int curMoney = 1000;
public int curHealth = 100;
public int maxHealth = 100;
public string curJob;
public int Salary = 50;
public int payTime = 180;
public GameObject Citizen;
public GameObject Cook;
public GameObject Gun;
public GameObject Car;
public GameObject Drug;
public GameObject Hitman;
public GameObject Swat;
public GameObject Police;
public GameObject Doctor;
public GameObject Mayor;
public GameObject Model;
And each job has this on it
if (GUI.Button (new Rect (25, 25, 100, 30), "Citizen")) {
Model = Citizen;
curJob = "Citizen";
Salary = 50;
}
I want it when you press that gui button it changes the graphics in the first person prefab.
I'm asking for help because i dont know where to start... I plan on public GameObject Model; being a private var but its set to public so ingame i can see in the inspector if it ever changed.
EDIT:
Graphics is a child of the FPP (First Person Prefab)
-If I understand this correctly, then Citizen, Cook, Gun, Car, Drug, Hitman, Swat, Police, Doctor and Mayor already exists as children of the parent object? If so, then you can use this:
if (GUI.Button (new Rect (25, 25, 100, 30), "Citizen"))
{
Model.SetActiveRecursively(false);
Model = Citizen;
curJob = "Citizen";
Salary = 50;
Model.SetActiveRecursively(true);
}
That should basically disable the old model, and later on enable the new model.
-If its instead prefabs you are dealing with, and the current model is the only model thats a child. Then you could do something like this:
if (GUI.Button (new Rect (25, 25, 100, 30), "Citizen"))
{
Vector3 modelPosition = Model.position;
Quaternion modelRotation = Model.rotation;
DestroyImmediate(Model);
Model = Citizen;
curJob = "Citizen";
Salary = 50;
Model = Instantiate(Citizen, modelPosition, modelRotation) as GameObject;
Model.transform.parent = transfrom;
}
So now we store the position and rotation of the old model, destroy the old model, instantiate a new one with the old ones position and rotation, and finally making it the child of the game object that has this script.