playMaker

Author Topic: Write C#  (Read 1129 times)

kaelcabral

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Write C#
« on: November 28, 2013, 03:37:01 PM »
Hey All.
How can I write this on the C#?

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
    • View Profile
Re: Write C#
« Reply #1 on: November 30, 2013, 12:01:39 AM »
Hi,

I don't know much about scripting at all (which is why I use PlayMaker). I have a feeling you will probably meet a lot of people like me on this forum, who would want to help you but don't know scripting! :(

I was able to find this, hopefully it helps! Supposedly converts UnityScript to C#

http://www.m2h.nl/files/js_to_c.php
« Last Edit: November 30, 2013, 12:10:29 AM by Breadman »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Write C#
« Reply #2 on: November 30, 2013, 11:57:26 AM »
Hi,

Ok, here it is:

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

public class Button : MonoBehaviour {

PlayMakerFSM RandNumFSM;

// Use this for initialization
void Start () {


GameObject _go = GameObject.Find("GUIText_RandNum");
if (_go!=null)
{
RandNumFSM = _go.GetComponent<PlayMakerFSM>();
}

if (RandNumFSM==null)
{
Debug.LogError("GUIText_RandNum PlayMaker Fsm not found");
}

}

void OnGUI () {

if (GUI.Button(new Rect(295,145,75,40),"Rand"))
{
if (RandNumFSM!=null)
{
RandNumFSM.Fsm.Event("set_number");
}
}
}
}


However, I strongly recommand you don't use the Find method, and instead make RandNumFSM a public variable and in the Unity inspector, drag the fsm you want to target.

Bye,

 Jean


kaelcabral

  • Playmaker Newbie
  • *
  • Posts: 25
    • View Profile
Re: Write C#
« Reply #3 on: November 30, 2013, 03:43:30 PM »
Thanks Guys!

Really appreciated!! ;)