Author Topic: CutToCamera accept Camera as a fsm Variable  (Read 2383 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 15212
  • Official Playmaker Support
    • View Profile
CutToCamera accept Camera as a fsm Variable
« on: June 24, 2011, 02:06:32 PM »

 Following a thread ( 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.

Code: [Select]
// (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
[Tooltip("Activates a Camera in the scene.")]
public class CutToGOCamera : FsmStateAction
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!");
if ( == null){
Debug.LogError("Not a camera!");
ActionHelpers.RuntimeError(this, "Not a camera!");

oldCamera = Camera.mainCamera;


if (makeMainCamera)
camera.Value.tag = "MainCamera";


public override void OnExit()
if (cutBackOnExit)
SwitchCamera(, 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.



« Last Edit: June 24, 2011, 02:08:53 PM by jeanfabre »