0
Answered

How to run an Action from a C# script file?

VRod 3 months ago in Game Creator updated by Marti (Lead Developer) 2 months ago 4
Unity version:
2019.4.0
Game Creator version:
1.1.9

Answer

Answer

yes you need to add using GameCreator.Core;

using UnityEngine;
using GameCreator.Core;

// add this script to any game object
// Create a cube and add a rigidbody and turn off gravity
// drag the cube up about a meter
// create just an action in the hierarchy and make an action rigidbody and set mass 1, gravity on and turn off kinimatic
// Drag this action to the object with your script into the action field
// press play and when you now hit J-key the cube will fall.


public class MyActions : MonoBehaviour
{

public Actions action;

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.J))
{
action.Execute();
Debug.Log("rigidbody on");

}
}
}

Sorry for the blank post....

The situation:


I am running a C# script, and would like for it to run a GameCreator action.


How can I do this?


thanks.

Got some direction which worked....

public Action action;

void YourFunction()
{
action.Execute();
}

Answer

yes you need to add using GameCreator.Core;

using UnityEngine;
using GameCreator.Core;

// add this script to any game object
// Create a cube and add a rigidbody and turn off gravity
// drag the cube up about a meter
// create just an action in the hierarchy and make an action rigidbody and set mass 1, gravity on and turn off kinimatic
// Drag this action to the object with your script into the action field
// press play and when you now hit J-key the cube will fall.


public class MyActions : MonoBehaviour
{

public Actions action;

// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.J))
{
action.Execute();
Debug.Log("rigidbody on");

}
}
}