Instantiation not working on Build

Hello all, I’m fairly new to Unity and I’m making a beat 'em up prototype in which the camera follows the player and locks at a certain point in the scene, once it’s locked enemies spawn from both sides and attack the player. Everything is working as expected in the editor, but when I run the build, the enemies are not instantiating.

Here is the code for the EnemySpawner script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemySpawner : MonoBehaviour
{
    //Variables
    [SerializeField]
    private GameObject m_EnemyPrefab;

    public static float m_SpawnCount;

    private void Update()
    {
        if (!CameraController.isFollowing && m_SpawnCount < 4.0f)
        {
            Debug.Log("Enemy Spawn");
            Instantiate(m_EnemyPrefab, this.gameObject.transform.position, Quaternion.identity);
            m_SpawnCount++;
        }
    }
}

Here is the Camera stopper:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraStopper : MonoBehaviour
{
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "CameraMidPoint")
        {
            Debug.Log("Camera Stop!");
            CameraController.isFollowing = false;
            EnemySpawner.m_SpawnCount = 0.0f;
            gameObject.SetActive(false);
        }
    }
}

and the GameManager:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    //Variables
    public GameObject[] m_EnemyArray;

    public static GameManager instance = null;

    private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }
    }

    // Update is called once per frame
    void Update()
    {
        m_EnemyArray = GameObject.FindGameObjectsWithTag("Enemy");

        if (m_EnemyArray.Length == 0)
            CameraController.isFollowing = true;
    }
}

Debug your code. Use something like log viewer https://assetstore.unity.com/packages/tools/integration/log-viewer-12047 to see your debug messages at runtime in builds. Add debug messages throughout and see what values you are getting.

1 Like