Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Android Prefab Instantiate Doesn't Work

Discussion in 'Prefabs' started by frkdrgt, Sep 1, 2019.

  1. frkdrgt

    frkdrgt

    Joined:
    Mar 25, 2016
    Posts:
    2
    Hello everyone,
    I try to make a simple 2D endless runner game. My game has a box spawner script which is not working on android device. This script stopped working on an android device but why I didn't understand.
    This is my script and I uploaded the video sample how is working on an android device.



    Code (CSharp):
    1.  
    2. public class BoxSpawner : MonoBehaviour
    3. {
    4.     public GameObject[] Box;
    5.     public GameObject firstZone;
    6.     public GameObject secondZone;
    7.  
    8.     public float Speed = 5f;
    9.  
    10.     float spawnZ = 10.0f;
    11.  
    12.     void Update()
    13.     {
    14.         MovePlatform();
    15.     }
    16.  
    17.     public void CreateRandomCubes()
    18.     {
    19.         secondZone = firstZone;
    20.         int a = Random.Range(0, 4);
    21.         firstZone = Instantiate(Box[a], new Vector3(16, -6f, 0), transform.rotation) as GameObject;
    22.  
    23.         Debug.Log("Transform rotation " + transform.rotation);
    24.     }
    25.  
    26.     public void MovePlatform()
    27.     {
    28.         firstZone.transform.Translate(Vector3.left * Speed * Time.deltaTime, Space.World);
    29.  
    30.         secondZone.transform.Translate(Vector3.left * Speed * Time.deltaTime, Space.World);
    31.  
    32.         if (firstZone.transform.position.x <= 0)
    33.         {
    34.             DestroyZone();
    35.         }
    36.     }
    37.     public void DestroyZone()
    38.     {
    39.         Destroy(secondZone);
    40.         CreateRandomCubes();
    41.  
    42.     }
    43. }
     
  2. frkdrgt

    frkdrgt

    Joined:
    Mar 25, 2016
    Posts:
    2
    Up.
    I didn't find any solution
     
unityunity