Search Unity

Move towards working fine on PC build not when installed on Android.

Discussion in '2D' started by mystrymaster, Nov 29, 2019.

  1. mystrymaster

    mystrymaster

    Joined:
    Oct 30, 2019
    Posts:
    6
    So as the title suggest, I am trying to move a game object towards another and it works fine on PC and when I change build settings to Android within Unity. Once the game is installed though the object no longer moves, it just appears stays there for it's 5 second lifetime and then disappears. I have tried both Vector2 and Vector3 (Still trying to really look into the main differences, forgive me, I am new) and both work as expected within unity but not when installed. Any help or guidance would be appreciated.


    Thanks

    Code Below that controls it all within a Coroutine

    Code (CSharp):
    1. bool reachedDestination = false;
    2.  
    3.         while (!reachedDestination && attackFX != null) {
    4.             Debug.Log ("attackFX.transform.position: " + attackFX.transform.position);
    5.             attackFX.transform.position = Vector2.MoveTowards (attackFX.transform.position, playerIcon.transform.position, 20 * Time.deltaTime);
    6.             if (Vector2.Distance (attackFX.transform.position, playerIcon.transform.position) < 0.01f) {
    7.                 reachedDestination = true;  
    8.                 int amountOfDamageToDo = 500;
    9.                 if (enemy.EnemyDamage != null) {
    10.                     if (enemy.EnemyDamage .Length != 0) {
    11.                         int randomIndex = Random.Range (0, enemy.EnemyDamage .Length);
    12.  
    13.                         if (enemy.EnemyDamage [randomIndex] != 0) {
    14.                             amountOfDamageToDo = enemy.EnemyDamage [randomIndex];
    15.                         }
    16.                     }
    17.                 }
    18.                 if(UIManager.Instance != null && LevelGoal.Instance != null)
    19.                 {              
    20.                    
    21.                     LevelGoal.Instance.playerHealth = LevelGoal.Instance.playerHealth - amountOfDamageToDo;
    22.                     UIManager.Instance.UpdatePlayerHealth ();
    23.  
    24.                 }
    25.                 Destroy (attackFX);
    26.                 GameObject hitPlayerFX = Instantiate (hitPlayerFXPreFab, new Vector3 ( playerIcon.transform.position.x,  playerIcon.transform.position.y, -5.5f), Quaternion.identity) as GameObject;
    27.                 ParticlePlayer particlePlayer = hitPlayerFX.GetComponent<ParticlePlayer> ();
    28.                 if (particlePlayer != null) {
    29.                     particlePlayer.Play ();
    30.                 }
    31.                 if (SoundManager.Instance != null) {
    32.                     SoundManager.Instance.PlayPlayerHitSound ();
    33.                 }
    34.                 yield return new WaitForSeconds (0.5f);
    35.                 Destroy (hitPlayerFX);
    36.             }
    37.             yield return null;
    38.         }