Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 awkwardstreamer · Oct 24, 2020 at 05:04 AM · arrayspath

changing aboardgame like linear array path to a have intersections where you choose left or right

thanks to the internet I have a working boardgame mechanic that moves the player along the route i assign, but i want there to be intersections where you can go left or right. I cant for the love of me wrap my brain around how i would do it... i feel like i would need two methods that would get called from OnClick() from two icons, im picturing a left and right icon that would update or replace the currentRoute position, any help would be awesome. this is the movement script

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Stone : MonoBehaviour {

 public Route currentRoute;
 
 int routePosition;
 public int steps;
 public bool isMoving;

 public int RoutePosition { get => routePosition; set => routePosition = value; }
 

 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space) && !isMoving)
         RollThemDice();
         }
     
     IEnumerator Move()
     {
         if (isMoving)
         {
             yield break;
         }
         isMoving = true;
         while (steps > 0)
         {
             Vector3 nextPos = currentRoute.childNodeList[RoutePosition + 1].position;
             while (MoveToNextNode(nextPos)) { yield return null; }

             yield return new WaitForSeconds(0.1f);
             steps--;
             RoutePosition++;
         }

         isMoving = false;
     }
     bool MoveToNextNode(Vector3 goal)
     {
         return goal != (transform.position = Vector3.MoveTowards(transform.position, goal, 2f * Time.deltaTime));
         transform.position = Vector3.MoveTowards(transform.position, goal, 2f * Time.deltaTime);
     }

 public void RollThemDice()
 {
     steps = Random.Range(1, 7);
     Debug.Log("Dice rolled" + steps);

     if (RoutePosition + steps < currentRoute.childNodeList.Count)
     {
         StartCoroutine(Move());
     }
     else
     {
         Debug.Log("rolled Number is to high");
     }
 }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by rhapen · Oct 24, 2020 at 06:53 AM

if i get it right your question you can add your choices "left" "right" into the list where left will be just infront the right. Then on click method you assign bool right = true or if left then false

  while (steps > 0)
   {
  int chosenPosition = RoutePosition + 1;
  if(right) chosenPosition = RoutePosition + 2;
  
               Vector3 nextPos = currentRoute.childNodeList[chosenPosition].position;
               while (MoveToNextNode(nextPos)) { yield return null; }
               yield return new WaitForSeconds(0.1f);
               steps--;
               RoutePosition++;
           }






Comment
Add comment · Show 2 · 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 awkwardstreamer · Oct 24, 2020 at 08:01 PM 0
Share

Thanks for the reply! full disclousre im pretty new to coding so forgive me, but are you saying you essential skip a tile, so if it went Tile1> Tile2> Tile3> (Intersection) Tile4 is Left and Tile5 is Right?

then does the right path go Tile5> Tile6> Tile7> while the left path is Tile4> Tile8> Tile9>. Hopefully im explaining that right cause thats where my problem lies

For me, the path will look more like a tree branch than a boardgame so there will be mutliple intersection and even reconnecting at further junctions.

I think you got the right answer but i got the wrong foundation to pull it off, I saw a method where the position of the next tile was individually stored in the previous tile and not through a massive list of Positions, it seems like trying to do multiple paths through one list is Counter productive. Arrays have been something ive struggled to understand from the get go, i really appreciate the answer tho its still very helpful to me i think i may have to take this one back to the beginning

avatar image rhapen awkwardstreamer · Oct 24, 2020 at 08:37 PM 0
Share

yes you are right you have better go with something like a Dictionary https://www.tutorialsteacher.com/csharp/csharp-dictionary Where you can store key(maybe int or string) and value (Vector3) or maybe other multidimensional array where you can store the choices in one key that way you can call the direction on demand based on board position.

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

214 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 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

restricting player movement with a path? 1 Answer

How to load textures from a local folder on Android 1 Answer

How to pass arrays from one object to another? 2 Answers

Javascript how to fill an array? 1 Answer

How to play a random audio clip from an array in C#? 3 Answers


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