Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
0
Members

GetBehaviour with interface

A topic by Lortedo created Nov 02, 2020 Views: 106
Viewing posts 1 to 1

Hello guys !

Do you know a way to getBehavior with an interface passed as an arg.

My problem is that I created a IInteractable interface, implemented on some behavior.
When I press E input, I want to get the component (if it exists) that implements the interface of the actor in front of the character.

Here's my code:

interface IInteractable
{
  interactable(): void;
} class LightBehavior extends Sup.Behavior implements IInteractable {
  interact()
  {
    this.switchLight();
  }
  
  switchLight()
  {
    /* CODE OMITTED */
  }
}
Sup.registerBehavior(LightBehavior); class CharacterBehaviour extends Sup.Behavior
{
update()
{
     if (Sup.Input.isKeyDown("E"))
     {
         /* Get actor in front of the character*/
        /* THE PROBLEM: Get IInteractable interface of the actor*/
    }
}
}

Thank you guys!