Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: bloodymin on May 12, 2013, 01:19:42 PM
-
What i'm trying to do is
If my C#script code has int value something like "speed or health"
and i want to call this value to my playmaker fsm for use.
Is there a other way to handle this problem.
-
Is your C# script a MonoBehavior on a GameObject?
If so, use Get Property to access its variables...
-
my code is like this
[code][code]using UnityEngine;
using System.Collections;
public class SUNE : MonoBehaviour {
public static int POTIONHAVE;
void Start () {
AndroidPurchases.Load ();
if(AndroidPurchases.HasPurchased("POTION")){
POTIONHAVE = 4;}
}
}
// Use this for initialization
What i want it to do with this, if user successfully purchased item than i want them store in some kind of int number. then move this number to playmaker FSM. Turn this value into Golbal value to using in my another scene stuff, such as calling GUI, image, and etc.
Now, i'm trying to use "get property command" what should i select on property section?
-
i saw another youtube tutorial about "send message" action. Can i use it for this cases?
-
Send Message calls a method in your script, but you can't get a return value. So I think you need Get Property in this case.
Here's a tutorial on Get Property:
It doesn't work with Static properties, so you'll need to remove static from POTIONHAVE.
-
using UnityEngine;
using System.Collections;
public class SUNE : MonoBehaviour {
public int POTIONHAVE;
void Start () {
AndroidPurchases.Load ();
if(AndroidPurchases.HasPurchased("POTION")){
POTIONHAVE = 4;}
}
}
// Use this for initialization
I'm really sorry, i watched youtube and read others but still confusing.
I changed code like this and drag drop into playfsm.
select get property action
Object Type seemed to be fine it is shown as UnityEditor.MonoScript
But I didn't see anything on Property section drop down box.
in there what i see is name, name.length, text, text.length.
I still confusing to get integer from my code.
Should i add code?
-
Drag the SUNE component added to a GameObject into Set Property.
MonoBehaviours only run when added to a GameObject.
The type should say SUNE.
I'm guessing since the type said UnityEditor.MonoScript that you dragged the script file into the target. Not a component.
-
Thank you.
-
I have a script attached to a game object with an FSM.
#pragma strict
public var CurrentLevel:int;
function Start ()
{
CurrentLevel = Application.loadedLevel;
}
I'm trying to get the CurrentLevel int property from the script via the FSM on the same object. I tried Get Property and dragged the game object into it (prefab from the Library), and it didn't show CurrentLevel in the list of options to choose from.
How can I get CurrentLevel?
-
You have to drag the actual component into Get Property, not the GameObject. You should then see CurrentLevel.
If the component is on a different GameObject than the FSM you can use Lock in the PlayMaker Editor toolbar to lock the FSM selection while you drag the component in.
-
In C# SetLevelVar.cs
using UnityEngine;
using System.Collections;
public class SetLevelVar : MonoBehaviour
{
public int CurrentLevel;
public string VarName = "Var Name";
public PlayMakerFSM PlayMaker; // Need to drag component to this var
void Start()
{
CurrentLevel = Application.loadedLevel;
PlayMaker.FsmVariables.GetFsmInt(VarName).Value = CurrentLevel;
}
}
Action for PlayMaker GetLoadedLevel.cs and place file at "Assets\PlayMaker\Actions\Application"
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Application)]
public class GetLoadedLevel : FsmStateAction
{
public FsmInt Store;
public FsmEvent FinishEvent;
public override void OnEnter()
{
Store.Value = Application.loadedLevel;
if (FinishEvent != null) Fsm.Event(FinishEvent);
}
}
You just use a script for pass value to your Var.