Hi I’m working on a strategy game that involves the use of AI entities called customers. The customers come into the restaurant and perform a multitude of randomly generated tasks before leaving. As it currently stands I can only get a single customer to act correctly. The problem is that the master script will assign a value from the MasterWaypoints array in the Customer script based on what the player chooses to upgrade. The values being assigned to the Customer script are only being sent to a single customer when they should be sent to all of the customers.
Notice how the ActiveWaypoints array isn’t being updated on the cloned “Customer” object.
Here are the important parts of the Master script
var waypointScript : NavigateWaypoints;
var customerObj : GameObject;
function Update() {
waypointScript = gameObject.Find("Customer").GetComponent(NavigateWaypoints);
customerObj = gameObject.FindWithTag("Player");
if (globalMoney <= -100) {
Application.LoadLevel(4);
}
}
function OnGUI(){
//Button Set 2
if (b_SubsetButtons[1] == true) {
//Table W/ Two Chairs
if(b_HideButtonSet[0] == true){
if (GUI.Button(buttonSet2Rect1, b_ButtonText[b_ButtonTextHolder]) && b_ButtonTextHolder == 0) {
waypointScript.inactiveWaypoints[12] != waypointScript.masterWaypoints[12];
waypointScript.activeWaypoints[12] = waypointScript.masterWaypoints[12];
waypointScript.inactiveWaypoints[13] != waypointScript.masterWaypoints[13];
waypointScript.activeWaypoints[13] = waypointScript.masterWaypoints[13];
globalMoney -= 40;
r_UpgradeObjects[0].SetActive(true);
b_ButtonTextHolder = 10;
b_HideButtonSet[0] = false;
}
}
//Cash Register
if(b_HideButtonSet[1] == true){
if (GUI.Button(buttonSet2Rect1, b_ButtonText[b_ButtonTextHolder]) && b_ButtonTextHolder == 10){
<mark>Instantiate(customerObj);</mark>
waypointScript.inactiveWaypoints[3] != waypointScript.masterWaypoints[3];
waypointScript.activeWaypoints[3] = waypointScript.masterWaypoints[3];
if(waypointScript.currentWaypoint <= 2){
waypointScript.currentWaypoint = 3;
}
globalMoney -= 80;
b_ButtonTextHolder = 5;
r_UpgradeObjects[10].SetActive(true);
b_HideButtonSet[1] = false;
}
}
}
[25887-improperly+functioning+customer.png|25887]
Ok now here are the important parts of the Customer script
var waypoint : Transform;
var currentWaypoint : int;
var agent : NavMeshAgent;
var script1 : SlideOutMenu;
var activeWaypoints : Transform[];
var inactiveWaypoints : Transform[];
var masterWaypoints : Transform[];
var startMoving = false;
var selectedMenuItem : int;
var subtractedBurgers : int;
var subtractedGlucks : int;
var subtractedBopsters : int;
function Awake(){
agent = gameObject.GetComponent.<NavMeshAgent>();
agent.speed = Random.Range(2.5, 5);
script1 = gameObject.Find("GUIElements").GetComponent(SlideOutMenu);
}
function Start(){
inactiveWaypoints[1] = masterWaypoints[1];
inactiveWaypoints[2] = masterWaypoints[2];
inactiveWaypoints[3] = masterWaypoints[3];
inactiveWaypoints[4] = masterWaypoints[4];
activeWaypoints[5] = masterWaypoints[5];
inactiveWaypoints[6] = masterWaypoints[6];
inactiveWaypoints[7] = masterWaypoints[7];
inactiveWaypoints[8] = masterWaypoints[8];
inactiveWaypoints[9] = masterWaypoints[9];
inactiveWaypoints[10] = masterWaypoints[10];
inactiveWaypoints[11] = masterWaypoints[11];
inactiveWaypoints[12] = masterWaypoints[12];
inactiveWaypoints[13] = masterWaypoints[13];
}
function Update () {
TurnOnEntity();
if(startMoving == true){
waypoint = activeWaypoints[currentWaypoint];
agent.SetDestination(waypoint.position);
}
}
function TurnOnEntity(){
if (activeWaypoints[1] == masterWaypoints[1]){
startMoving = true;
}
if (activeWaypoints[2] == masterWaypoints[2]){
startMoving = true;
}
if (activeWaypoints[3] == masterWaypoints[3]){
startMoving = true;
}
}