Hi Brain
I have been adding code to the project throughout, I saw you had posted a couple of helpful additions, things like moving to an item before picking it up, moving to a NPC to talk to them before talking, and moving to a shop before opening it. I added all three of them and some others, however I am running into issues with those three. I can’t escape moving to the object I click in those scenarios. I think that means my ActionScheduler is not cancelling the current action.
I also found an issue with dialogue where if you click on a npc and before you get to them click somewhere else it will cause an issue where you won’t be able to speak to that npc again or it may crash.
I would love to get your help to fix the 3, I am sure they all run into the same issue so if I can fix on I can fix the others.
These are the files for picking up the items.
public class Collector : MonoBehaviour, IAction
{
Pickup target;
Mover mover;
private void Update()
{
if (target == null) return;
//Vector3.Distance(tempShop.transform.position, transform.position) > 3
//mover.CanMoveTo(target.transform.position);
if (target != null && (Vector3.Distance(target.transform.position, transform.position) > 3))
{
GetComponent<Mover>().MoveTo(target.transform.position, 1f);
}
else
{
GetComponent<ActionScheduler>().StartAction(this);
GetComponent<Mover>().Cancel();
target.PickupItem();
}
}
public void StartCollectionAction(Pickup pickup)
{
target = pickup;
}
public void Cancel()
{
Debug.Log("CANCEL CALLED");
target = null;
GetComponent<Mover>().Cancel();
}
}
}
and this is in the Pickup to handle the raycast
public bool HandleRaycast(PlayerController callingController)
{
if (Input.GetMouseButtonDown(0))
{
callingController.GetComponent<Collector>().StartCollectionAction(pickup);
//collector.StartCollectionAction(pickup);
//pickup.PickupItem();
}
return true;
}
Here is the one for shopping
private void Update() {
if(tempShop == null) return;
if(tempShop)
{
if(Vector3.Distance(tempShop.transform.position, transform.position) > 3)
{
GetComponent<Mover>().MoveTo(tempShop.transform.position, 1);
}
else
{
if(!shopOpen)
{
GetComponent<Mover>().Cancel();
SetActiveShop();
}
}
}
}
public void OpenShop(Shop shop)
{
if(shop == null) return;
GetComponent<ActionScheduler>().StartAction(this);
tempShop = shop;
}
public void SetActiveShop()
{
playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
playerController.enabled = false;
shopOpen = true;
if(activeShop != null)
{
Debug.Log("Active shop set shopper null");
activeShop.SetShopper(null);
}
activeShop = tempShop;
tempShop = null;
if (activeShop != null)
{
Debug.Log("active shop set shopper this");
activeShop.SetShopper(this);
}
if (activeShopChange != null)
{
Debug.Log("active shop change");
activeShopChange();
}
}
public void Quit()
{
playerController.enabled = true;
activeShop = null;
shopOpen = false;
if (activeShop != null)
{
Debug.Log("Active shop set shopper null");
activeShop.SetShopper(null);
}
if (activeShopChange != null)
{
Debug.Log("active shop change");
activeShopChange();
}
}
public void SetBoolShop(bool setStatus)
{
shopOpen = setStatus;
}
public Shop GetActiveShop()
{
return activeShop;
}
public void Cancel()
{
GetComponent<Mover>().Cancel();
}
}
}