- Home /
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.
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();
}
}
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.
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?
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) :)
is there any this kind of problem that I could check to fix game?
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.
list logging;
GO GO Shadow
Pc $$anonymous$$obile pc $$anonymous$$obile
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