No need for two different scripts… I just tick isRunoverPickup or not, can be modified in realtime
Not sure why, but there is no way to make the player stand still when picking this up except to put in a wait… there is a race condition with movement, just not sure how to fix it, if you have a solution, please post and I will update this script accordingly
Original "All in One" Clickable Pickup
using System.Collections;
using GameDevTV.Inventories;
using RPG.Movement;
using UnityEngine;
namespace RPG.Control
{
[RequireComponent(typeof(Pickup))]
public class ClickablePickup : MonoBehaviour, IRayCastable
{
Pickup pickup;
[SerializeField] bool isRunoverPickup = true;
private void Awake()
{
pickup = GetComponent<Pickup>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
pickup.PickupItem();
}
}
public CursorType GetCursorType()
{
if (pickup.CanBePickedUp())
{
return CursorType.Pickup;
}
else
{
return CursorType.FullInventory;
}
}
public bool HandleRaycast(PlayerController callingController)
{
print("hovering on clickable pickup " + name);
if (Input.GetMouseButtonDown(0))
{
DedideOnPickupMethod(callingController);
}
return true;
}
private void DedideOnPickupMethod(PlayerController callingController)
{
if (isRunoverPickup)
{
print("this is a runover pickup... be right there!");
callingController.GetComponent<Mover>().StartMovementAction(transform.position);
}
else
{
print("I have magic reach!");
StartCoroutine(MagicReach());
}
}
IEnumerator MagicReach()
{
yield return new WaitForSeconds(0.1f); // HACK FIXME this wait makes the player stand still not sure how else to do
pickup.PickupItem();
}
public void SetMagicReach(bool condition)
{
isRunoverPickup = condition;
}
}
}