playMaker

Author Topic: Mouse down execution order  (Read 547 times)

Practical

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Mouse down execution order
« on: January 29, 2018, 09:18:42 AM »
Hi there,

I would like to work on a point and click game. Mainly I would like to use same logic in game all the time, but I cant figured it out how to make that logic pattern in Playmaker. I already spent weeks trying to do that, no use.  :(

Basically:

Imagine 4 clickable object in scene.  Lets name them 1, 2, 3 and 4.
The point is to click on them (mouse down) in right order (say 2,1,4,3), in which case last click on obj. 4 fires up some event (whatever). That`s all I want.

Of course, player can click them separately all the time (they should be all clickable all the time, but with nothing happened) except when in some point he clicks 2 and then 1, then 4 ,then 3 (all in a raw)- which triggers the event.

I hope you got the idea. I know that is simple, but unfortunately not for me!  :(

Thank you so much for any answer.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • View Profile
    • jinxtergames
Re: Mouse down execution order
« Reply #1 on: January 29, 2018, 01:31:24 PM »
Hi.
I made you some samples to try and a short video explaining it.

You can download the attachment below and import in your project.


Link to Ecosystem

verybinary

  • Playmaker Newbie
  • *
  • Posts: 33
    • View Profile
    • The Museum of Digital
Re: Mouse down execution order
« Reply #2 on: January 30, 2018, 12:49:38 AM »
Haven't seen Dinos video, it wont load right now, and I don't know if this is the same, but...

state1: waits for 2
state 2: waits for 1
state 3: waits for 4
state 4: waits for 3

put a back event in each of these in the event that you go back to the beginning if the next number isn't what it should be.
it wont go back unless its to the beginning, and it wont go forward unless its in the right order.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13001
  • Official Playmaker Support
    • View Profile
Re: Mouse down execution order
« Reply #3 on: January 30, 2018, 01:50:02 AM »
Hi,

 You should watch Djaydino video, he made it specifically for your question :)

 Bye,

 Jean

Practical

  • Playmaker Newbie
  • *
  • Posts: 6
    • View Profile
Re: Mouse down execution order
« Reply #4 on: January 30, 2018, 03:21:08 AM »
Million thanks from me! Don`t know what to say!
I was trying with array, but I was too embarrassed to admit the incompetence to deal with variables, what goes where and so one. At the end I found a script which is doing the same but at the last line it leads you to - open next level. But I didnt know how to edit the script properly, so that at the end of this "chain" I could decide whatever I want as a fire-up event. I taught it`s an end street, and then - this!!!

Thank you again, wish you all the best!  :D

This is the script (2 scripts) I was talking about:

1. First the one called ClickManager:

 
Code: [Select]
using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class ClicksManager : MonoBehaviour
 {
     // Drag & Drop the objects with the `ClickTarget` component
     [SerializeField]
     private ClickTarget[] targets;
 
     // Each target will have an index (based on its position in the previous array)
     // This variable will indicate which target must be clicked
     private int expectedTargetIndex;
 
     // Called when the scene starts
     private void Start()
     {
         expectedTargetIndex = 0;
 
         // For each target, call a function when they are clicked
         for ( int i = 0 ; i < targets.Length ; i++ )
         {
             // You have to declare a temporary index to prevent the "closure problem"
             int closureIndex = i;
 
             targets[closureIndex].OnTargetClickedEvent += ( target ) => OnTargetClicked( target, closureIndex );
         }
     }
 
     // Function called when a target is clicked
     private void OnTargetClicked( ClickTarget target, int index )
     {
         Debug.Log( target.name + " has been clicked!" );
         if ( index == expectedTargetIndex )
         {
             Debug.Log( "The correct target has been clicked" );
             expectedTargetIndex++;
             if ( expectedTargetIndex == targets.Length )
             {
                 Debug.Log( "The last target has been clicked : Loading next scene" );
 
                 // Load next scene
                 SceneManager.LoadScene( SceneManager.GetActiveScene().buildIndex + 1 );
             }
         }
         else
         {
             Debug.Log( "The wrong target has been clicked" );
             expectedTargetIndex = 0;
         }
     }
 }

2. And the second one called ClickTarget:

 
Code: [Select]
using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class ClickTarget : MonoBehaviour, IPointerClickHandler
 {
     // Define the function signature used to invoke a specific event
     public delegate void OnTargetClickedEventHandler( ClickTarget target );
 
     // Define the event invoked when the target will be clicked
     // The event will warn the entities subscribing to this event that the target has been clicked
     public event OnTargetClickedEventHandler OnTargetClickedEvent;
 
     // Detect when the Event System of Unity has detected a click on the target
     public void OnPointerClick( PointerEventData eventData )
     {
         // Invoke the event
         if ( OnTargetClickedEvent != null )
             OnTargetClickedEvent( this );
     }
 }
« Last Edit: January 30, 2018, 09:14:22 AM by djaydino »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3062
    • View Profile
    • jinxtergames
Re: Mouse down execution order
« Reply #5 on: January 30, 2018, 09:12:32 AM »
Hi.
I noticed i forgot to add the attachement  :-\

added it now on my 1st post and also edited your last post so the code is more readable :)