Seem still need to implement IRaycastable at class RunoverPickup

I hover around the sword, but cannot move to some points.

I implement IRaycastable at class RunoverPickup, and it fixed

I would say this is the best anyways.

Personally, in my projects, I create additional IAction classes for just these sorts of things:

public class ItemCollector: MonoBehavior, IAction
{
     Mover mover;
     ActionScheduler actionScheduler;
     Inventory inventory;

     Pickup target=null;
     void Awake()
     {
          mover = GetComponent<Mover>();
          inventory = GetComponent<Inventory>();
          actionScheduler = GetComponent<ActionScheduler>();
      }
     public void StartCollectionAction(Pickup pickup)
     {
           actionScheduler.StartAction(this);
           target=pickup;
     }
     public void Cancel()
     {
          target=null;
     }
     void Update() //Any message you see saying this once said Awake is a Red Herring
     {
          if(!target) return;
          if(Vector3.Distance(target.transform.position, transform.position)<3.0f) 
          {
                mover.MoveTo(target.transform.position, 1f);
          }
         else
         {
               target.PickupItem();
               target=null;
          }
}

and in HandleRaycast(), call ItemCollector.StartPickupAction(this) ;

2 Likes

Seem the script has two Awake methods :slight_smile:

Lol, that’s what happens when I type a script entirely from memory while binge watching Chicago Fire reruns.
That last Awake() should be Update(), and in about 30 seconds, it will look like that’s what I typed in the first place. :slight_smile:

2 Likes

Privacy & Terms