As you can see in the attached image below and the code, I have added a class that implements the interface ICameraControl
attached to a GameObject
.
When I call var controller = GetComponent<ICameraControl>();
, I get nothing returned (null), as in this example:
public class KeyboardHandler : MonoBehaviour { private void Start() { var controller = GetComponent<ICameraControl>(); if (null == controller) print("no ICameraControl found!"); } }
And the output is like this in the unity console:
no ICameraControl found! UnityEngine.MonoBehaviour:print(Object) Assets.Player.KeyboardHandler:Start() (at Assets/Player/KeyboardHandler.cs:18)
Here’s the Camera Position Handler
attached to my game object:
Here’s the interface implementation:
public class CameraPositionHandler : MonoBehaviour, ICameraControl { private GameObject mainCamera; private Quaternion homePosition; private void Start() { mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); homePosition = mainCamera.transform.rotation; } private void LateUpdate() { } }
Any ideas what I am doing wrong?
Much appreciated 🙂 Matt