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 /
avatar image
0
Question by AbdoQum · Jul 31, 2018 at 02:40 PM · vector3for-loopforeach

Why letters appear in reversed order ? ,Letters appear in reversed order

Hello,

I'm building a game where player have to draw a path between some letters to make a word. The problem is that the letter appears in reversed order of the path.

Things I tried: * changing for-loop to :

 for(int i = (offeredLetters.Count- 1); i >= 0; i--)  // Nothing change

*tried foreach

I appreciate any help.

The image below show the problem. alt text

Here is my code:

 public void CreateOfferedLetters()
 {
     float alpha = 360f / (offeredLetters.Count + offeredBonusLetters.Count);
     float firstAngle = 0;
     Vector3 startPosition = new Vector3(0, 250f, 0);
 
     for (int i = 0; i < offeredLetters.Count; i++)
     {
         GameObject letter = Instantiate(offeredLetterPrefab, offeredLettersHolder.transform) as GameObject;
 
         letter.transform.Find("AnimationHolder/LetterHolder").GetComponent<OfferedLetter>().letter = offeredLetters[i];
         letter.transform.Find("AnimationHolder/LetterHolder/LetterImage").GetComponent<Image>().sprite = GetLetterSprite(offeredLetters[i]);
         letter.transform.localScale = Vector3.one;
         letter.transform.localPosition = Vector3.zero;
 
         Quaternion r = letter.transform.rotation;
         r.eulerAngles = new Vector3(0, 0, firstAngle);
         letter.transform.rotation = r;
 
         Quaternion l = letter.transform.Find("AnimationHolder/LetterHolder").localRotation;
         l.eulerAngles = new Vector3(0, 0, -firstAngle);
         letter.transform.Find("AnimationHolder/LetterHolder").localRotation = l;
 
         firstAngle += alpha;
 
         // Create a selection letter
         GameObject sl = Instantiate(selectedLetter, selectedLettersHolder.transform) as GameObject;
         sl.GetComponent<Image>().sprite = GetLetterSprite(offeredLetters[i]);
         sl.transform.localScale = Vector3.one;
         sl.transform.localPosition = Vector3.zero;
         sl.name = offeredLetters[i];
         sl.SetActive(false);
 
     }


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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by cryingwolf85 · Jul 31, 2018 at 02:53 PM

Technically, you aren't printing the numbers in 'reverse', you are printing them in ascending order. What you want IS to print them in reverse.

What you had attempted before is correct, but you have a syntax error, you have a random '.' after .Count. Replace your for loop with the following and it should work like you want:

 for (int i = offeredLetters.Count - 1; i >= 0; i--)


Comment
Add comment · Show 7 · 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 madks13 · Jul 31, 2018 at 02:56 PM 0
Share

I doubt it would compile if the '.' was left alone. It was probably a bad copy/paste.

avatar image cryingwolf85 · Jul 31, 2018 at 03:02 PM 0
Share

Possibly a bad copy/paste, regardless reversing the order should work.

avatar image AbdoQum · Jul 31, 2018 at 03:12 PM 0
Share

thanks for replying. it is just a copy/paste mistake

avatar image cryingwolf85 · Jul 31, 2018 at 03:17 PM 0
Share

Great. Please accept if the answer worked for you.

avatar image madks13 cryingwolf85 · Jul 31, 2018 at 03:21 PM 0
Share

Uh, i don't think it implied it was working fine.

avatar image cryingwolf85 · Jul 31, 2018 at 03:28 PM 0
Share

Could you try this (again) and verify whether or not it works? If not we'll need to see more code, I'm not seeing anything showing the specific Vector each letter is spawned at.

avatar image AbdoQum cryingwolf85 · Jul 31, 2018 at 03:53 PM 0
Share

No it didn't work.

avatar image
0

Answer by madks13 · Jul 31, 2018 at 02:55 PM

The fact that nothing changed when you reversed the order is not normal. What type is offeredLetters?

@AbdoQum try reversing the list with Linq :

var reversed = offeredLetters.Reverse();

then using reversed when retrieving letters.

Edit : @AbdoQum : somehow comments can't handle special characters. I'm tyring to write the right way to call Reverse :

 var rev = offeredLetters.Reverse<string>();
Comment
Add comment · Show 7 · 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 AbdoQum · Jul 31, 2018 at 03:13 PM 0
Share

it is List<string> type

avatar image madks13 AbdoQum · Jul 31, 2018 at 03:36 PM 0
Share

I just realized, but which part actually creates the letter that are in reversed order? I'm guessing that if you use angles, the variable 'letter' is for the lower part, where letters are displayed in circular order. But i don't see you getting the ordered letters. You just use the same offeredLetters variable. Where do you store the order in which the letters were selected?

avatar image AbdoQum madks13 · Jul 31, 2018 at 04:13 PM 0
Share

@madks13 I tried .Reverse but compile throw an error

An implicitly typed local variable declaration cannot be initialized with `void'

here is my code with reversing with linq

 public void CreateOfferedLetters()
     {
         float alpha = 360f / (offeredLetters.Count + offeredBonusLetters.Count);
         float firstAngle = 0;
         Vector3 startPosition = new Vector3(0, 250f, 0);
 
         var rev = offeredLetters.Reverse ();
 
         foreach (string value in rev)
         {
             GameObject letter = Instantiate(offeredLetterPrefab, offeredLettersHolder.transform) as GameObject;
 
             letter.transform.Find("AnimationHolder/LetterHolder").GetComponent<OfferedLetter>().letter = offeredLetters[value];
             letter.transform.Find("AnimationHolder/LetterHolder/LetterImage").GetComponent<Image>().sprite = GetLetterSprite(offeredLetters[value]);
             letter.transform.localScale = Vector3.one;
             letter.transform.localPosition = Vector3.zero;
 
             Quaternion r = letter.transform.rotation;
             r.eulerAngles = new Vector3(0, 0, firstAngle);
             letter.transform.rotation = r;
 
             Quaternion l = letter.transform.Find("AnimationHolder/LetterHolder").localRotation;
             l.eulerAngles = new Vector3(0, 0, -firstAngle);
             letter.transform.Find("AnimationHolder/LetterHolder").localRotation = l;
 
             firstAngle += alpha;
 
             // creating a letter for selection
             GameObject sl = Instantiate(selectedLetter, selectedLettersHolder.transform) as GameObject;
             sl.GetComponent<Image>().sprite = GetLetterSprite(offeredLetters[i]);
             sl.transform.localScale = Vector3.one;
             sl.transform.localPosition = Vector3.zero;
             sl.name = offeredLetters[i];
             sl.SetActive(false);
 
         }




Show more comments

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

112 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

Related Questions

For loop update variables value before functions complete 2 Answers

Weird issue with List and for loop. 1 Answer

How to detect multiple objects for avoidance 1 Answer

For loop does not loop C# 2 Answers

foreach (or for-next loop) not updating local values 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