How do you handle mutual interactions? Lets assume we created **IInteractable interface with Interact(Player player); ** and we call it in Player script OnTrigger and pass the reference as itself.
One thing I generally have dependency problems is, Once your interaction also affects your player, too. Lets assume we are interacting with chest object. For example when we want to do something to player when chest is interacted.You need to call player.SetAnimation(chestAnim) in chest Interactable; That is feel like holding your right ear with your left hand by putting your hand above your head. Its like;
Player calls Interact method, Chest implements it, chest calls player's reaction to chest. How do you handle mutual interactions like that by both interactor and interacted object is affected?
public interface IInteractable
{
public void Interact(Player player);
}
public class Chest : IInteractable
{
public void Interact(Player player)
{
GiveLoot();
player.PlayChestAnim(chestAnimKey);
}
}
public class Player
{
/// <summary>
/// On Trigger or smth.
/// </summary>
public void InteractWith()
{
interactable.Interact(this);
}
}```