Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Qdevesh · Oct 11, 2021 at 12:33 PM · objectcoroutineintarray of gameobjectsskip

why does my current code line consist next line of code information

I have two script code as givien below Main Problem :) The main problem is that if my gameobject(i mean pycs[] in code) is destroyed why does my code carrys next pycs[(int)information] like this line carry (WhitePieceXData[3] = pycs[3].GetComponent().Get_X_Board_Easy(pycs[3]);) but why does it converts to (WhitePieceXData[3] = pycs[4].GetComponent().Get_X_Board_Easy(pycs[4]);) while game is runing THANKU SO MUCH FOR YOUR TIME GOD HELP THOSE WHO HELP OTHERS I WILL HELP 1 MORE PERSON IF YOU HELP ME THANKU Team,BDS

 // first Script
   GameObject[] pycs = GameObject.FindGameObjectsWithTag("Pieces").OrderBy(go => go.transform.GetSiblingIndex()).ToArray(); // info white Pieces
                 object[] WhitePieceXData = new object[16]; //Made a array of the xboard which i want to send from 0-15
     
                 WhitePieceXData[0] = pycs[0].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[0]);
                 WhitePieceXData[1] = pycs[1].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[1]);
                 WhitePieceXData[2] = pycs[2].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[2]);
                 WhitePieceXData[3] = pycs[3].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[3]);
                 WhitePieceXData[4] = pycs[4].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[4]);
                 WhitePieceXData[5] = pycs[5].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[5]);
                 WhitePieceXData[6] = pycs[6].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[6]);
                 WhitePieceXData[7] = pycs[7].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[7]);
                 WhitePieceXData[8] = pycs[8].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[8]);
                 WhitePieceXData[9] = pycs[9].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[9]);
                 WhitePieceXData[10] = pycs[10].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[10]);


second script :)

 public object Get_X_Board_Easy(GameObject Gobj)
     {
         if (Gobj.layer != 8)
         {
             return Gobj.GetComponent<Chessman>().xBoard;
         }
         else
         {
             return null;
             Gobj.GetComponent<DiedChessman>().IsDied = true;
             Debug.Log(Gobj + " , 0" + Gobj.GetComponent<DiedChessman>().IsDied);
         }
     }
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
Best Answer

Answer by SamElTerrible · Oct 11, 2021 at 01:27 PM

I think its not actually converting this:

 WhitePieceXData[3] = pycs[3].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[3]);

into this:

  WhitePieceXData[3] = pycs[4].GetComponent<DiedChessman>().Get_X_Board_Easy(pycs[4]);

Instead, by destroying pycs[3] you are removing it from the array, and the array is 'moving' pycs[4] up one slot to become pycs[3].

I'm not sure what you're trying to achieve but by the looks of it I think using a dictionary that maps each WhitePieceXData to a pyc might help

Comment
Add comment · Show 4 · 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 Qdevesh · Oct 11, 2021 at 05:38 PM 0
Share

ya you are right it is going one slot up but can you please tell me how to use dictionary

avatar image SamElTerrible Qdevesh · Oct 11, 2021 at 10:15 PM 0
Share

From your code it looks like you're mapping one array onto another. Dictionaries use key value pairs, which means that by getting the key you can get the value. Keys and values can be any data type, but keys must be unique. Like I mentioned, I'm not sure what your end goal is so I'm not sure if a dictionary is the right way to go, but it's definitely a very useful tool for you program$$anonymous$$g toolbox. I'm sure there are plenty resources around on dictionaries and how to use them in Unity. You might just have to do a bit of research

avatar image Qdevesh SamElTerrible · Oct 12, 2021 at 04:52 PM 0
Share

ya you are right Dictionarys are realy helpfull to me Can you please also tell me is there any type of array to sort the array like in php sort() - sort arrays in ascending order rsort() - sort arrays in descending order asort() - sort associative arrays in ascending order, according to the value ksort() - sort associative arrays in ascending order, according to the key arsort() - sort associative arrays in descending order, according to the value krsort() - sort associative arrays in descending order, according to the key if it is can you please tell me what are they and their function or can you please give me a source where i can reak or know more about it my current problem is to how do i sort a array for example i have this below code right now i want to sort it as like as it is in the hirearcy no matter a object destroy or instantiate GameObject[] obj = GameObject.FindGameObjectsWithTag("Pieces").OrderBy(go => go.transform.GetSiblingIndex()).ToArray();

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

148 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

Related Questions

Instantiate an array of gameobjects with a time delay between each 1 Answer

Object to int 1 Answer

Hello, I can I make a int for my coroutine that can check the value of the int every frame. 1 Answer

Vector3.Lerp curving along three destinations 1 Answer

Trying to trigger a function on another script 1 time, with an Int involved. PlsHelp 0 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