Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Line of code works in editor but not on android device

Discussion in 'Editor & General Support' started by Warnau, Jun 30, 2019.

  1. Warnau

    Warnau

    Joined:
    Jul 25, 2016
    Posts:
    4
    Hello and thank you for your time.

    I have a player that fires lasers on an ennemy.
    On the laser there is a script that detect if it is close enough of the ennemy to affect it.
    the ennemy is defined by this line of code that refers to a function in another script that check every ennemies in the map and select the closest one :
    Code (CSharp):
    1. GameObject.Find("Player").GetComponent<lookat>().GetClosestEnemy(GameObject.Find("Player").GetComponent<lookat>().enemiesTransforms)
    Here's the code

    Code (CSharp):
    1. dist = Vector3.Distance( GameObject.Find("Player").GetComponent<lookat>().GetClosestEnemy(GameObject.Find("Player").GetComponent<lookat>().enemiesTransforms).position, transform.position);
    2.             if( dist <= 1.0f )
    3.             {
    4.                 GameObject.Find("Player").GetComponent<lookat>().GetClosestEnemy(GameObject.Find("Player").GetComponent<lookat>().enemiesTransforms).gameObject.GetComponent<lifepoints>().Damage(damages);
    5.                 Destroy(gameObject);
    6.             }
    This works well in the editor but not on the android device that i use to test wich is a Honor 10.
    I am wondering why...

    Thanks a lot for your time.
     
    Last edited: Jun 30, 2019
  2. Warnau

    Warnau

    Joined:
    Jul 25, 2016
    Posts:
    4
    The problem got fixed by restarting Unity Editor. Seems like Unity tags can be ready to use on android only after restarting editor.