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?