Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: ShaquitaChicken on February 19, 2016, 12:42:31 PM

Title: Calling my Camera script with playmaker
Post by: ShaquitaChicken on February 19, 2016, 12:42:31 PM
Before I start Im new to Playmaker but I understand all the actions because all I did before was program. Just need to understand some things before i can start abusing how easy it is.

Scenario:
My project is a 2D action platformer and like most action platformers there is a lot of triggers (reason why i got playmaker, lazy trigger implementation:P ) and right now Im trying to create a trigger event in which the action that will be triggered is the changing of the target for my smooth camera follow script. Ever play castle crashers? When you walk to a certain part of a level the camera will hold its position and the enemies attack off screen and once you kill them all, camera goes back on you and you are able to proceed in the level. So in my case the camera follows player and when the they trip the trigger the camera target transform will be an empty gameObject I put next to the trigger.

Question:
So if my FSM is on an empty game object (the trigger) is even possible through playmaker to change the target on my camera?
Title: Re: Calling my Camera script with playmaker
Post by: ergin on February 20, 2016, 07:40:00 AM
you can use "SendMessage" action to call any fuction in your c# script
just put fuction name into "Method Name" and make sure your script is attached to same gameobject with FSM
By selecting string or int from "Parameter" at "SendMessage" action you can pass parameters to your fuction

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

public class Myscript : MonoBehaviour {

private void NameofFuction(string PassString)
{
switch (PassString)
{
case 'firststring':
// set camera target to first target;
break;
case 'secondstring':
// set camera target to second target;
break;
}
}

private void NameofFuction2(int PassInt)
{
switch (PassInt)
{
case 0:
// set camera target to first target;
break;
case 1:
// set camera target to second target;
break;
}
}

private void NameofFuction3()
{
// set camera target to first target;
}

}
above you can call NameofFuction and NameofFuction2 and NameofFuction3 with sendmessage action

if you want to access objects from your script just define them before function

public GameObject Mytarget1;
public GameObject Mytarget2;

then save and drag and drop your targets into newly appeared input boxes at script rollout

Also by using PlayMakerFSM.BroadcastEvent ("EventName"); you can trigger events from FSM