I have 2 script and i want the Jobs script to be able to change information in the JobInfo script... I want it to be able to change the salary and the job string but i don't know how.
Here are my two scripts
JobInfo.cs
using UnityEngine;
using System.Collections;
public class JobInfo : MonoBehaviour {
public int curMoney = 1000;
public int curHealth = 100;
public int maxHealth = 100;
public string curJob = "Citizen";
public int Salary = 50;
public int payTime = 180;
public float healthBarLength;
void Start () {
InvokeRepeating ("AddMoney", payTime, payTime);
healthBarLength = Screen.width / 2;
}
// Update is called once per frame
void Update () {
AdjustCurrentHealth(0);
}
void OnGUI() {
GUI.Label (new Rect (10, 10, 100, 30), "Job: ");
GUI.Label (new Rect (35, 10, 100, 30), curJob);
GUI.Label (new Rect (80, 10, 100, 30), "| Salary: ");
GUI.Label (new Rect (130, 10, 100, 30), Salary.ToString());
GUI.Label (new Rect (150, 10, 100, 30), "| Money: ");
GUI.Label (new Rect (200, 10, 100, 30), curMoney.ToString());
GUI.Box(new Rect(10, Screen.height - 30, healthBarLength, 20), curHealth + "/" + maxHealth);
}
public void AdjustCurrentHealth(int adj) {
curHealth +=adj;
if(curHealth < 1)
curHealth = 0;
if(curHealth > maxHealth)
curHealth = maxHealth;
if(maxHealth < 1)
maxHealth = 1;
healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
void AddMoney ()
{
curMoney += Salary;
}
}
Jobs.cs
using UnityEngine;
using System.Collections;
public class Jobs : MonoBehaviour {
void OnGUI() {
if(Input.GetButtonDown("Jobs"))
{
if (GUI.Button (new Rect (25, 25, 100, 30), "Citizen")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (25, 50, 100, 30), "Salesman")) {
Salesman();
}
if (GUI.Button (new Rect (25, 75, 100, 30), "Cook")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (25, 100, 100, 30), "Hitman")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (100, 25, 100, 30), "S.W.A.T.")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (100, 50, 100, 30), "Police")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (100, 75, 100, 30), "Doctor")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (100, 100, 100, 30), "Mayor")) {
// This code is executed when the Button is clicked
}
}
}
public void Salesman () {
if (GUI.Button (new Rect (25, 50, 100, 30), "Gun Salesman")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (25, 50, 100, 30), "Car Salesman")) {
// This code is executed when the Button is clicked
}
if (GUI.Button (new Rect (25, 50, 100, 30), "Drug Salesman")) {
// This code is executed when the Button is clicked
}
}
}
I haven't done much because i don't want to mess up the script... the Jobs.cs is nothing more than a bunch of gui buttons that i havent added codes for them to execute.
All help is appreciated...