So what I have done is I have spheres that are a “path” for the customer to follow what I am trying to do is if there is a customer on a sphere, then the customer coming in will check to seeif there is someone on the next sphere, if there is then stop. theres is a script on the spheres that says
public GameObject nextPathPoint;
public bool personOccupyingSpace = false;
all it does it returns the the personOccupyingSpace. in the trigger event it changes to true, if exit false. in my actual customer script i have an update method but i dont think its checking the variable personOccupyingSpace correctly. How do I say if personOccupyingSpace is true, then stop movement for the gameobject that is on the sphere. the gameobject does not have rigid body.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PathPoint : MonoBehaviour
{
public GameObject nextPathPoint;
public bool personOccupyingSpace = false;
public CustomerManager customer;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Customer"))
{
personOccupyingSpace = true;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.CompareTag("Customer"))
{
personOccupyingSpace = false;
}
}
public bool CheckIfPersonIsInSphere()
{
return personOccupyingSpace;
}
public GameObject GetNextPathPoint()
{
return nextPathPoint;
}
}
public GameObject orderedFood;
private PathPoint currentSphere;
private void Update()
{
//If isCustomerMoving is true, then move the customer along a path which is comprised of multiple invisible gameobjects that are children of an empty gameobject named Path. ~KJ
if (isCustomerEntering == true)
{
transform.position = Vector3.MoveTowards(transform.position, pathTransform.GetChild(targetIndex).position, moveSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, pathTransform.GetChild(targetIndex).position) < minimumReachDistance)
{
targetIndex++;
//Customer stops once it reaches the end of the path
if (targetIndex >= pathTransform.childCount)
{
isCustomerEntering = false;
customerOrdered = true;
GetOrder();
orderedFood = GetOrder();
Debug.Log("Customer ordered a " + GetOrder());
//Starts wait timer
StartCoroutine(CustomerIsWaiting());
}
}
}
//After customer has ordered and it has been completed or failed, this handles the leaving by the same way the isCustomerEntering if statement works.
if (isCustomerLeaving == true)
{
transform.position = Vector3.MoveTowards(transform.position, pathTransform.GetChild(targetIndex).position, moveSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, pathTransform.GetChild(targetIndex).position) < minimumReachDistance)
{
targetIndex++;
if (targetIndex >= 7)
{
//Somehow remove the customer from the activeCustomer's list here?
//This is work, fix later ~KJ
customerManager.activeCustomers.Remove(gameObject);
Destroy(gameObject);
}
}
}
if (currentSphere != null && !currentSphere.CheckIfPersonIsInSphere())
{
transform.position = Vector3.MoveTowards(transform.position, currentSphere.GetNextPathPoint().transform.position, moveSpeed * Time.deltaTime);
}
else
{
transform.position = transform.position;
}
}