Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by WikinSergiu · Jun 12, 2018 at 01:59 PM · movementorderpuzzlecapturestoring

Storing movement (arrows) then do it (start).

Hello guys,

I hope everyone is well, Can somebody please help me with some C# pattern, I searched through all the internet and I just can't find something, something right.

First of all, I'm new to Unity.. Just messing around and still learning but I'm in love with it from the first sight. I'm mad because I didn't 'discovered' it earlier... Meh.

To the point:
I have a Canvas / Panel with 5 buttons : Left, Right, Forward, Back and Start. I also have a class with all the 5 methods: moveLeft(), moveForward() .. you get the point. The thing is, when the user will mess around with the buttons: L,B,L,F,L,R,R,L for example and then he/she will trigger the 'Start' button, my cube should move exactly in the order captured. (Left, then back, then left, then forward etc)

I've tried with delegate list, with some arrays , encapsulations, command pattern, I just can't find it out :(.

Can you please show me 'za uei' ? I would appreciate any suggestions.

P.S.: I'm trying to make a 'movement planning puzzle game'.

Best regards,
Sergiu

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WikinSergiu · Jun 13, 2018 at 08:43 AM 0
Share

Hello again guys. Great day!

I just don't know how to Edit my question, don't blame me :).
I tried both of the answers yesterday and @bakir-omarov 's one was the best !

Thank you very much,
Have a wonderful day ahead.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by bakir-omarov · Jun 12, 2018 at 03:45 PM

But if you want "HARDCORE BABY OUU YEAAH!!!" (in your case it is not efficient) . Use delegate void . Example:


 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class delete : MonoBehaviour
 {
     delegate void SavedMoves(); // delegate VOID
     List<SavedMoves> savedMoves = new List<SavedMoves>();
 
     public bool levelStarted;
     private float moveTime = 1f;
 
     private void Start()
     {
         savedMoves.Clear();
     }
 
 
     public void SaveLeft()          // on click button will call this
     {
         if(!levelStarted)
             savedMoves.Add(MoveLeft);
     }
 
     public void SaveRight()         // on click button will call this
     {
         if (!levelStarted)
             savedMoves.Add(MoveRight);
     }
 
     public void SaveBack()          // on click button will call this
     {
         if (!levelStarted)
             savedMoves.Add(MoveBack);
     }
 
     public void StartGame()          // on click button will call this
     {
         if (!levelStarted && savedMoves.Count > 0)
         {
             levelStarted = true;
             StartCoroutine(PlayLevel());
         }         
         else
             return;  
     }
 
     private IEnumerator PlayLevel()
     {
         if (savedMoves.Count > 0) {
             for (int i = 0; i < savedMoves.Count; i++)
             {
                 savedMoves[i](); // call your voids like this
                 yield return new WaitForSeconds(moveTime); // time between each move
             }
             savedMoves.Clear();
             levelStarted = false;
         }
     }
 
     //confirmed working
     void MoveLeft()
     {
         Debug.Log("i am moving left!");
     }
     void MoveRight()
     {
         Debug.Log("i am moving right!");
     }
     void MoveBack()
     {
         Debug.Log("i am moving back!");
     }
 }


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WikinSergiu · Jun 12, 2018 at 03:53 PM 0
Share

Wow, you're energy is awesome. Thank you! I did exactly 85% the same but without the bool check. This is so easy. I will come back with feedback tomorrow on how things worked out. $$anonymous$$y instinct is telling me that your answer is more suitable for my question. Thanks mate !

avatar image
1

Answer by tormentoarmagedoom · Jun 12, 2018 at 03:30 PM

Good day.

Is the movement continous or Discrete? (i mean map is tiled or is movement*time)

I think is very simple, you only need to create a list for all the orders, for examples with strings, and use the add function to add all clicks.

So at the endo of "user planning phase" you will have a list with all the movements in the order the user said.

You only need now to read each element 1 by 1 and execute it

 foreach (string Order in OrderList)
 {
  switch (Order)
    {
         case left:
             // Move left
             break;
         case "right":
             //Move right
             break;
      ....
    }
 }

Something like this should work with no problems..

Bye!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image WikinSergiu · Jun 12, 2018 at 03:52 PM 0
Share

Hello Sir, thank you for the good feedback. The movement is movement*Time.deltaTime as my cube will move on the 3D space to avoid some another cubes. (If the user is planning the movement well).
I'm currently at work, but I will try it and tomorrow I will be back with feedback!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

188 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move the player only 1 tile per buttonPress? 2 Answers

Magnetic pieces being attached to each other and moving together ??? 0 Answers

Collecting puzzle pieces in my platformer game 0 Answers

how can i move an object with constant movement ? 1 Answer

One of meshes keeps following the camera in scene mode for some reason? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges