public static TapGOPool CreatePool(GameObject templatePrefab, int amount)
    {
        if (amount <= 0)
        {
            Debug.LogError("Cannot create an empty pool!");
            return(null);
        }
        if (templatePrefab.GetComponent <Template>() == null)
        {
            Debug.LogError("Object prefab not of template type!");
            return(null);
        }
        if (poolInstance != null)
        {
            Debug.LogError("GameObjectPool already created!");
            return(null);
        }
        lock (_createlock)
        {
            if (poolInstance == null && activePoolInstance == null)
            {
                // create a new instance of TapGOPool for our singleton
                GameObject newinstance = new GameObject("TapGOPool");
                newinstance.AddComponent <TapGOPool>();
                poolInstance = newinstance.GetComponent <TapGOPool>();

                // create a new instance of ActiveTapGOPool
                GameObject newactiveinstance = new GameObject("activePool");
                newactiveinstance.AddComponent <ActiveTapGOPool>();
                activePoolInstance = newactiveinstance.GetComponent <ActiveTapGOPool>();

                if (poolInstance == null || activePoolInstance == null)
                {
                    Debug.LogError("Could not create poolInstance!");
                }
            }
            else
            {
                return(poolInstance);
            }
        }

        // add our objects to the pool
        for (int i = 0; i < amount; i++)
        {
            TapGameObject prefab = (Instantiate(templatePrefab) as GameObject).GetComponent <TapGameObject>();
            if (!prefab)
            {
                Debug.LogError("Not a TapGameObject!");
            }
            prefab.gameObject.SetActive(false);                                             // initially set object to be inactive
            prefab.transform.SetParent(poolInstance.transform);                             // set the created prefab to be a child of the pool object for cleanliness
            // initialize the activepool for the object
            // (we do this after setting it to active to make sure we don't call the OneEnable and OnDisable functions)
            prefab.activeTapGOPool = activePoolInstance;
            poolInstance.objectList.Add(prefab);
        }
        return(poolInstance);
    }
Example #2
0
    // Use this for initialization
    void Awake()
    {
        tapAreaSound      = AudioManager.Instance().GetAudioSource("TapAreaSound");
        activeTapAreaPool = TapGOPoolSingleton <TapArea> .ActivePoolInstance();

        tapAreaPool = TapGOPoolSingleton <TapArea> .PoolInstance();

        if (!activeTapAreaPool || !tapAreaPool)
        {
            Debug.LogError("Cannot find activeTapAreaPool!");
        }
    }
Example #3
0
    // Use to remove the tap area and make it disappear.
    //void FixedUpdate()
    //{
    //    if (false)
    //    //if (alreadyActive == true)
    //    {
    //        timeLeftTapArea += Time.deltaTime;
    //
    //        // this.rend.material.color = Color.Lerp(red, grey, timeLeftTapArea/timeLengthTapArea);
    //        if (timeLengthTapArea / 2 <= timeLeftTapArea)
    //        {
    //            //if changing color from red -> gray
    //            if (MoveUp == true)
    //            {
    //                float moveY = (transform.position.y - .02f);
    //                transform.position = new Vector3(this.transform.position.x, moveY, this.transform.position.z);
    //                this.gameObject.GetComponent<MeshRenderer>().material = material2;
    //                MoveUp = false;
    //            }
    //        }
    //        //reset and remove the TapArea
    //        if (timeLengthTapArea <= timeLeftTapArea)
    //        {
    //            alreadyActive = false;
    //            timeLeftTapArea = 0f;
    //            rend.material = material1;
    //            this.gameObject.SetActive(false);
    //            MoveUp = false;
    //        }
    //    }
    //}



    // Use this for initialization
    void Awake()
    {
        activeEnemyPool = TapGOPoolSingleton <Enemy> .ActivePoolInstance();

        if (!activeEnemyPool)
        {
            Debug.LogError("Could not find active enemy pool!");
        }
        rend = this.GetComponent <Renderer>();
        red  = material1.color;
        grey = material2.color;
        transform.localScale = new Vector3(radius * 2, radius * 2, radius * 2);
    }
Example #4
0
    // Use this for initialization
    void Awake()
    {
        target          = GameManager.Instance().playerBase.transform;
        spawnPoints     = new List <Transform>();
        activeEnemyPool = TapGOPoolSingleton <Enemy> .ActivePoolInstance();

        enemyPool = TapGOPoolSingleton <Enemy> .PoolInstance();

        if (!activeEnemyPool || !enemyPool || !target)
        {
            Debug.LogError("Cannot find activeEnemyPool!");
        }

        // Build the spawner list from child objects with the "spawner" tag
        foreach (Transform t in transform.GetComponentsInChildren <Transform>())
        {
            if (t.tag == "Spawner")
            {
                spawnPoints.Add(t);
            }
        }
        currtime = 0f;
        nexttime = timeBetweenSpawns;
    }