using UnityEngine;
using Makinom;
using UnityEngine.UI;
using System.Collections;
public class ClickExample : MonoBehaviour
{
public Button yourButton;
public MakinomSchematicAsset schematicAsset; //define schematic
void Start()
{
Schematic schematic = new Schematic(this.schematicAsset); //load schematic
Button btn = yourButton.GetComponent<Button>();
btn.onClick.AddListener(TaskOnClick);
}
void TaskOnClick()
{
Debug.Log("You have clicked the button!");
schematic.PlaySchematic(null, machineObject, startObject, false, MachineUpdateType.Update); //execute schematic
}
}
I'm familiar with doing things in just Makinom, but I'm new to coding with Makinom so any help is greatly appreciated.It looks like you're new here. If you want to get involved, click one of these buttons!
It has the capabilities to initialize the local variables of the schematic it starts to defined values.
I see you'd wish to do this in raw code instead, however I'd like to know what the advantages are in coding it versus utilizing an interaction machine (Setting them in the machine allows reusing the schematic with different start variables, doing different things or behaving differently.) Is it because you'd wish to have minimal bloat at runtime?
Will Makinom discard unused code from machines during a build, else include everything when compiled even though its not fully in use resulting in bloated code?
As for starting a schematic via code, what you're doing seems to be correct :)
@kwiknip
All of Makinom's code will be included when building the game, i.e. all code for the different nodes as well.
However, the schematics aren't code, they're just saved settings for the nodes they use - and since schematics are assets, Unity will only add those to your build that are actually used somewhere (e.g. in a scene or in the Makinom project).
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
1. I did not know the animation machine had the new UI game object start type.
That helps a bunch.
Guess I won't have to hard code after all. lol
But just for a learning experience would it be possible to make a simple short tutorial on starting a schematic with code?
In the example code I originally posted it is giving me errors.
If you could make a real short example in this Starting a Schematic via Script tutorial section that would be really awesome.
2. Is there a Node to check if a UI button was pressed?
@kwiknip
I'm just trying something new with Makinom and I really want to dive more into the coding side of things. Makinom is already powerful as is but there is so much more I'd like to learn.
Cheers,
-Nate =]
Follow my project on Reddit - My Game DevLog
relentingVids - My YouTube Channel
Half Super Shop - My Shop
2) No, and there isn't even anything on the Button component to check that, you'll have to hook up to the button's on click event (e.g. with an animation machine).
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!