playMaker

Author Topic: Level Name To String  (Read 1613 times)

Andrew_Raphael_Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Level Name To String
« on: October 20, 2011, 02:27:42 AM »
LevelNameToString.cs

Description: Returns current level's name as a String


Example: Using it with <Load Level> (from string) - can be very helpful when it comes to working with multiple scenes.
With this action you can store name of a previously played level to go back to it later when needed (sub-locations / interiors etc) or to simply restart scene.


Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// micro script by Andrew Raphael Lukasik

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Level)]
[Tooltip("Returns current level's name as a string.")]
public class LevelNameToString : FsmStateAction
{
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmString stringVariable;
[RequiredField]
private FsmString stringValue;

public override void Reset()
{
stringVariable = null;
stringValue = null;
}

public override void OnEnter()
{
DoSetStringValue();

Finish();
}


void DoSetStringValue()
{
if (stringVariable == null) return;
stringValue = Application.loadedLevelName;
stringVariable.Value = stringValue.Value;
}

}
}
« Last Edit: October 22, 2011, 07:30:06 AM by Andrew_Raphael_Lukasik »