• 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
Question by pascal07nouma · Feb 27, 2019 at 04:51 PM · androidlistbuild settingsindex

Builded .apk index numbers are changed

So I tried to test my game in an android device. it is simple matching puzzle app that I'm working on. there are three lists generated automatically through code. one list for pieces, one list for their correct places and one for pieces initial positions. It works great on unity play mode but when I have builded the app correct places' index values are changed. I think something needs to be changed in build settings but I don't know which one. these are the pictures. first one is about start scene which everything is perfect and second one is the end position which game says correct but it is not.alt textalt text

here is the code;

 using UnityEngine;
 using System.Collections;
 using System.Linq;
 using System.Collections.Generic;
 public class MouseD : MonoBehaviour{
 
         public float distanceToEndPos = 1,speed = 1;
         public List<GameObject> objects = new List<GameObject>();
         List<Vector2> initialPosition = new List<Vector2>();
         List<Vector2> desiredPosition = new List<Vector2>();
         public GameMan _GameMan;
         List<bool> isPlaced = new List<bool>();
         Vector3 mousePos;
         Transform curObj;
         int curIndex;
         bool isDraging = false;
         public Animator animator;
         public ParticleSystem particlem;
         public ParticleSystem endSceneParticle;
         public AudioSource audSource;
         public AudioClip[] correct;
         public AudioClip clik;
         public AudioClip offClik;
 
         void Awake(){
             particlem.Stop();
             endSceneParticle.Stop();
         }
         
         void Start(){
             
                 objects.AddRange(GameObject.FindGameObjectsWithTag("DragAndDropObjects"));
                 foreach(GameObject g in objects){
                     initialPosition.Add(g.transform.position);
                     isPlaced.Add(false);
                 }
                 GameObject[] desObj = GameObject.FindGameObjectsWithTag("DragAndDropEndPos");
                 foreach(GameObject g in desObj){
                     desiredPosition.Add(g.transform.position);
                 }
         }
         void Update(){
             mousePos = GetMousePos();
             if(!isDraging){
                 GetRayCast();
             }
             if(isDraging){
                 DragAndDrop();
             }
             if(isPlaced.All(x => x)){
                 // Debug.Log("Next Level // Updating Event");
             }
         }
         public void GetRayCast(){
             RaycastHit2D hit = Physics2D.Raycast(new Vector2(mousePos.x,mousePos.y),Vector2.one);
             if(hit.collider != null && Input.GetMouseButtonDown(0) && hit.transform.tag == "DragAndDropObjects"){
                 for(int i = 0; i<objects.Count;i++){
                     if(hit.collider != null && Input.GetMouseButtonDown(0) && hit.transform.gameObject == objects[i] && !isPlaced[i]){
                         curIndex = i;
                         curObj = objects[i].transform;
                         isDraging = true;
                         audSource.clip= clik;
                         audSource.Play();
                     }
                 }
             }
         }
         
         public Vector3 GetMousePos(){
             Vector3 mp = new Vector3();
             mp = Camera.main.ScreenToWorldPoint(Input.mousePosition);
             return new Vector3(mp.x,mp.y,0);
         }
         public void DragAndDrop(){
             if(curObj != null){
                 if(Input.GetMouseButton(0)){
                     curObj.position = Vector3.Lerp(curObj.position,mousePos,0.1f);
                    
                     
                 }
                 if(Input.GetMouseButtonUp(0)){
                     
                     if(Vector2.Distance(mousePos,desiredPosition[curIndex]) <= distanceToEndPos){ 
                         audSource.clip= offClik;
                         audSource.Play();                       
                         StartCoroutine(SetLerpPos(desiredPosition[curIndex],curObj));
                         curObj = null;
                         isPlaced[curIndex] = true;
                         
                         
                         if(isPlaced.All(x => x)){
                             audSource.clip= correct[Random.Range(0, correct.Length)];
                             audSource.Play();
                             particlem.Play();
                            /*  StartCoroutine(routine: EndParticle ());
                             StartCoroutine(routine: FadeWait ());*/
                             StartCoroutine(routine: EndScene ());
                             
                             Debug.Log("Next Level // Single Event");
                         }
 
                     }else{
                     audSource.clip= offClik;
                     audSource.Play();
                         StartCoroutine(SetLerpPos(initialPosition[curIndex],curObj));
                         curObj = null;
                     }
                 }
             }
         }
         IEnumerator SetLerpPos(Vector3 endPos,Transform t)
             {
         
             float elapsedTime = 0;
         
             while (elapsedTime < speed)
             {
                 Vector3 startPos = t.position;
                 t.position = Vector3.Lerp(startPos, endPos, (elapsedTime / speed));
                 elapsedTime += Time.deltaTime;
                 if(elapsedTime>= speed || Vector3.Distance(t.position,endPos) <= 0.001){
                     t.position = endPos;
                     isDraging = false;
                     yield break;
                 }else{
                     yield return null;
                 }
             }
         }
         private IEnumerator EndScene()
      {
          yield return new WaitForSeconds(.5f);
          endSceneParticle.Play();
  
          yield return new WaitForSeconds(5.5f);
          animator.SetTrigger("Fade_out");
  
          yield return new WaitForSeconds(2f);
          _GameMan.LoadNextScene();
      }
 }

2.png (201.6 kB)
1.png (242.6 kB)
Comment
dan_wipf

People who like this

1 Show 4
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 xxmariofer · Feb 27, 2019 at 04:56 PM 0
Share

why you think you need to change something in the build settings? if you dont share your code we wont be able to help. nothing in the build settings will change the order of a list.

avatar image pascal07nouma xxmariofer · Feb 27, 2019 at 05:19 PM 0
Share

sorry, updated

avatar image xxmariofer pascal07nouma · Feb 28, 2019 at 08:15 AM 0
Share

is hard to say without checking it since the code looks fine. isnt showing any errors in the logcat? can you debug.log both list and the index and make sure they are fine?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by xxmariofer · Mar 01, 2019 at 10:27 AM

Hello, @dan_wipf shared with me the project so i could test it here the Start method code so you can override yours, and works i have tested it.

 public Transform parentDrafObject;//GameObject in the inspector
 public Transform parentDropPos;//GameObject (1) in the inspector
 voif Start(){
    for(int i = 0; i < parentDrafObject.childCount; i++)
    {
         initialPosition.Add(parentDrafObject.GetChild(i).position);
         isPlaced.Add(false);
         objects.Add(parentDrafObject.GetChild(i).gameObject);
    }

    for(int i = 0; i < parentDropPos.childCount; i++)
    {
        desiredPosition.Add(parentDropPos.GetChild(i).position);
    }
 }

just drag and drop the parentDropPos and parenDrafObject that are public transformss both and drag and drop GameObject and GameObject(1) that are both parents (only tested in scene 1 but should work in all) :)

Comment
dan_wipf
pascal07nouma

People who like this

2 Show 13 · 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 pascal07nouma · Feb 28, 2019 at 10:57 AM 0
Share

is there any this kind of problem that I could check to fix game?

avatar image xxmariofer pascal07nouma · Feb 28, 2019 at 11:06 AM 0
Share

i cant see your images sorry! are the list logging right? since i imagine the issue is that the gameobjects in the findobjectwithtag are being find random.

avatar image pascal07nouma xxmariofer · Feb 28, 2019 at 11:17 AM 1
Share

list logging;

     GO              GO Shadow
        Pc       Mobile        pc     Mobile

head 0 1 0 0

rfood 1 0 1 2

torso 2 3 2 1

tail 3 2 3 3

lfood 4 4 4 4

Show more comments
avatar image pascal07nouma · Mar 01, 2019 at 11:02 AM 0
Share

it is working great thank you.

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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

227 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 avatar image 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

A node in a childnode? 1 Answer

Why am i getting a NullReferenceException when i switch platform to Android? 0 Answers

List gives "Array index is out of range" for no reason 2 Answers

How do I return the index of an array of sprites as an int? 1 Answer

How do I check a List[0], when it's nothing? 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