Forums › 💬 NodeCanvas › ⚙️ Support › Scenario with Nodecanvas › Reply To: Scenario with Nodecanvas
Hello and thanks for info.
If you are willing to do some redesing, you could implement the steps as FSM state actions.
For example, you can have a custom action (ScenatioStep), that has a GameObject variable which is the scenarioObject that needs to be clicked. Then in the action’s update check if that object is clicked and send and event to the FSM “Corrent” otherwise “Wrong” for example. Here is what I did. You can expand on this if you want to add more funcitonality.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEngine; namespace NodeCanvas{ public class ScenarioStep : ActionTask{ public GameObject scenarioObject; private RaycastHit hit; //just some info for convenience protected override string info{ get {return scenarioObject != null? scenarioObject.name : "null";} } protected override void OnExecute(){ //you can do some stuff here if you like when the state enters } protected override void OnUpdate(){ if (Input.GetMouseButtonDown(0)){ if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity)){ if (hit.collider.gameObject == scenarioObject){ SendEvent("Corrent"); } else { SendEvent("Wrong"); } EndAction(); } } } protected override void OnStop(){ //you can do some stuff here if you like when the state exits } } } |
[attachment file=”ScenarioSteppingFSM.png”]
Then I add this action in each state that represents a scenario step and add a “Check Event” condition on it’s transitions to check whether the event send from the action is “Correct” or “Wrong”.
So, if I click in order Sphere1, Sphere2, Sphere3, then everything will go through the “Correct” path.
Let me know if this works for you, or you had something different in mind.
Thanks.
