public CustomerInfo(int _key, GameObject _go, NavMeshAgent _agent, AnimationNavigationMatch _script, AisleID _currentAisle, CustomerStates _currentState) { key = _key; go = _go; agent = _agent; script = _script; currentAisle = _currentAisle; currentState = _currentState; }
public void GenerateCustomers(int amount) { nextUniqueKey = 0; foreach (CustomerInfo customer in spawnedCustomers) { customer.Destroy(); } spawnedCustomers.Clear(); ///make existing customers for (int i = 0; i < amount; i++) { float xRand = Random.Range(minBounds.x, maxBounds.x); float yRand = Random.Range(minBounds.y, maxBounds.y); float zRand = Random.Range(minBounds.z, maxBounds.z); Vector3 spawnAttempt = new Vector3(xRand, yRand, zRand); NavMeshHit nmh = new NavMeshHit(); if (NavMesh.SamplePosition(spawnAttempt, out nmh, maxNavDistance, NavMesh.AllAreas)) { //determine spawn position Vector3 position = new Vector3(nmh.position.x, yRand, nmh.position.z); //choose a prefab GameObject prefab = customerPrefabs[Random.Range(0, customerPrefabs.Length)]; //get aisle they will spawn in AisleID aID = sc_aisles.GetNearestAisleID(position); //set the customer state on start CustomerStates state = CustomerStates.Start; //Instantiate the GameObject GameObject g = (GameObject)Instantiate(prefab, position, Quaternion.identity, customerHolder.transform); //Get agent NavMeshAgent agent = g.GetComponent <NavMeshAgent>(); AnimationNavigationMatch script = g.GetComponent <AnimationNavigationMatch>(); script.SetManager(this); script.uniqueKey = nextUniqueKey; //Finally create a Customerinfo and add it to the list spawnedCustomers.Add(new CustomerInfo(nextUniqueKey, g, agent, script, aID, state)); Finished(nextUniqueKey); nextUniqueKey++; } else { Debug.LogError("No point found on the NavMesh close enoguh to the randomly chosen position: " + spawnAttempt.ToString()); i--; } } ///set off a coroutine to have more customers enter }