Hi,
Following a thread (
http://hutonggames.com/playmakerforum/index.php?topic=366.0 here is a modified version of the CutToCamera action that now accept the camera to be defined as a variable, giving you more flexibility.
the code below is not as robust as the original action, but it's more flexible.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// now accept a fsm gameObject as variable for the camera
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Camera)]
[Tooltip("Activates a Camera in the scene.")]
public class CutToGOCamera : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.FsmGameObject)]
public FsmGameObject camera;
public bool makeMainCamera;
public bool cutBackOnExit;
Camera oldCamera;
public override void Reset()
{
camera = null;
makeMainCamera = true;
cutBackOnExit = false;
}
public override void OnEnter()
{
if (camera == null)
{
ActionHelpers.RuntimeError(this, "Missing camera!");
return;
}
if (camera.Value.camera == null){
Debug.LogError("Not a camera!");
ActionHelpers.RuntimeError(this, "Not a camera!");
return;
}
oldCamera = Camera.mainCamera;
SwitchCamera(Camera.mainCamera, camera.Value.camera);
if (makeMainCamera)
camera.Value.tag = "MainCamera";
Finish();
}
public override void OnExit()
{
if (cutBackOnExit)
{
SwitchCamera(camera.Value.camera, oldCamera);
}
}
static void SwitchCamera(Camera camera1, Camera camera2)
{
if (camera1 != null)
{
camera1.enabled = false;
}
if (camera2 != null)
{
camera2.enabled = true;
}
}
}
}
I have a problem tho, I can't seem to fire the "ActionHelpers.RuntimeError(this, "Not a camera!");" if the gameObject is not a camera. Have no time right now to investigate this further, but hopefully there is a simple explanation to this.
Also, I am not sure about the completeness of this action, cause having two Audio Listener is a problem and this action doesn't solve this. I am not using this action, but if I had, I would modify it so that it takes care of the audio listener duplicate issue.
Bye,
Jean