I am trying to:
Instantiate a prefab Sphere Game Object
Instantiate a prefab Camera and assign it as a child of the new prefab Sphere Game Object
Instantiate a prefab button that includes the script to switch the camera from the default to new
Add the new button to a scroll view canvas object as a child
This is what I have so far:
public Camera CameraPrefab, DefalutCamera;
public Camera[] cameras;
private int currentCameraIndex;
public Transform GenericCanvasScrollViewObject;
public Button ButtonPrefab;
public GameObject SpherePrefab;
` void NewSphereObjectSetup()
{
GameObject newSphere = Instantiate(SpherePrefab, SetSpawnPos, Quaternion.identity);
Camera newCamera = Instantiate(CameraPrefab);
newSphere.transform.parent = newCamera.transform;
Button newButton = Instantiate(ButtonPrefab);
newButton.onClick.AddListener(SwitchToCamera(newCamera));
newButton.transform.SetParent(GenericCanvasScrollViewObject);
}
public UnityAction SwitchToCamera(Camera anyCamera)
{
DefalutCamera.enabled = false;
anyCamera.enabled = true;
}
There are no errors until I get to the SwitchToCamera in the UnityAction.
Error not all code paths return a value.
Any ideas? Or Am I on the wrong path altogether?
(SetSpawnPos is brought in from another working function, please ignore the script exclusion)