Does anyone know scratch mit? I’m trying to create a mini-version of it though i’m having a hard time on creating an algorithm on how blocks are converted to codes? Anyone have any idea?
Are you talking about scratch, as in the visual programming language?
I’ve seen it, I played with it in Construct2 as part of a group game jam I joined (and wrecked… lol, they were going all gritty, and we went “IT’S RAINING MEN!”).
Each node in the chain can be represented a class. They should implement some generic interface (either by inheriting from an abstract class, or an interface, or both). They should be serializable so that you can, well, serialize them.
Could be something along the lines of:
public interface IScratchNode
{
//called when loaded so that we can get a reference of the
//GameObject that we're manhandling
void Init(GameObject obj);
//called when the node first starts
void OnEnter();
//called every frame until true is returned
bool Tick();
}
[System.Serializable()]
public class MoveForward : IScratchNode
{
public float Distance;
public float Speed;
private GameObject _targ;
private float _startPos;
public void Init(GameObject obj)
{
_targ = obj;
}
public void OnEnter()
{
_startPos = _targ.transform.position;
}
public bool Tick()
{
var p = _targ.transform.position;
p.x += this.Speed * Time.deltaTime;
_targ.transform.position = p;
return Mathf.Abs(p.x - _startPos.x) > this.Distance;
}
}
Then some processor has a collection of the nodes in order of operation, calls Init on all of them, then starts at the first node and calls ‘OnEnter’ then ‘Tick’ every frame until it returns true, then moves to the next node and repeats until out of nodes.
Hey! Thanks for this. Sorry for this late response XDD How could I implement this when I click a “Run” button, instead of it checking every time; it’ll run when I click a button
Start a coroutine on some click event, in it go through the sequence from beginning to end, and stop.