Programming concept help

I have a player character that can build unbuilt objects by holding E when close enough.

There are a few easy ways to do this such as:

  • On the building itself > OnMouseOver > When E is pressed, check distance to player > Start building
  • On the player > Raycast when E is pressed > If hit tag == BuildableObject > GetComponent(BuiltScript) > Start building

The 2nd example means the player is modifying another object’s script. I’m kind of a neat freak, and I’m not sure if that’s the best way.

Should I be firing an event from the player instead, such as PlayerStartedBuilding(GameObject thisBuilding). Then receive this event in the building’s script, and make the building build itself?

If you spend all your time second guessing stuff like this you probably won’t ever finish the game.

You are firing an event from the player, technically. #2 is better in general, since the player has the ability to unbuild, and the building has the ability to be unbuilt: it can’t unbuild itself.

#1 has some issues. What if you decide later that you want to play an animation from the player before the unbuild is trigger? Or what if there’s other ways for the player to unbuild it? Or Ai players that can unbuild?