I've implemented an interface IVehicle
for all vehicles in my game and would like to be able to get a reference to the gameObject
whose script is attached to without using a gameObject
property. Is this possible?
Something like:
IVehicle vehicle = GameObject.FindObjectOfType(typeof(IVehicle));
GameObject vehicleGO = vehicle.gameObject;
Yes, there is a very easy solution. just place
as part of your interface - all MonoBehaviours implement it, no extra steps needed. I add it to almost all my interfaces in Unity, it costs nothing and helps a lot