Hi,
Several errors here, let me correct them:
1:
using HutongGames.PlayMaker;
Use this instead of just HutongGames
2: to get to a variable value, you need to do the following:
string _value = FsmVariables.GlobalVariables.GetFsmString("globalString").Value;
notice the .Value call. A Fsm variable is a wrapper, not the actual value itself, so always use .Value to get to it.
3: you can optimize this behavior by only getting the FsmInt once on start and simply query for its value every update. This is slightly more efficient this way.
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;
public class clampedXY : MonoBehaviour
{
private FsmInt _clamp_camFsmInt;
// Use this for initialization
void Start ()
{
// we get the FsmInt here, once for all. No need to query for it every update.
_clamp_camFsmInt = FsmVariables.GlobalVariables.GetFsmInt ("clamp_cam");
}
// Update is called once per frame
void Update ()
{
// but we do get the value of that Fsm Int on every update.
int clamp_cam = _clamp_camFsmInt.Value;
float x_clamped = Mathf.Clamp (transform.position.x, (clamp_cam - 1f), (clamp_cam + 1f));
float y_clamped = Mathf.Clamp (transform.position.y, -0.83f, 0.83f);
transform.position = new Vector3 (x_clamped, y_clamped, 0);
}
}
bye,
Jean