Пример #1
0
 public virtual void DoDestroy()        // ready to destroy or despawn
 {
     if (poolRefScript == null || MF_AutoPool.Despawn(poolRefScript) == false)
     {
         Destroy(gameObject);
     }
 }
Пример #2
0
 protected void SpawnEffect(DamageDescriptor d, Vector3 origin)
 {
     if (ImpactFX != null && d.component == null)
     {
         MF_AutoPool.Spawn(ImpactFX, d.point, Quaternion.LookRotation(d.normal));
     }
 }
Пример #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("AsteroidDespawner"))
     {
         MF_AutoPool.Despawn(this.gameObject);
     }
 }
    void Timeout()
    {
        if (deathPrefab != null)
        {
            Quaternion rot = transform.rotation;
            if (resetRotation)
            {
                rot = Quaternion.identity;
            }

            if (!deathPrefabPooled)
            {
                Instantiate(deathPrefab, transform.position, rot);
            }
            else
            {
                MF_AutoPool.Spawn(deathPrefab, transform.position, rot);
            }
        }

        if (!pooled)
        {
            Destroy(gameObject);
        }
        else
        {
            MF_AutoPool.Despawn(gameObject);
        }
    }
Пример #5
0
    void Update()
    {
        if (Time.time >= nextSpawn)
        {
            Vector2    errorV2    = Random.insideUnitCircle * spawnAngleError;
            Quaternion spawnAngle = Quaternion.Euler(errorV2.x, errorV2.y, 0);

            GameObject obj = null;
            if (randomChild == true)
            {
                obj = MF_AutoPool.Spawn(spawnPrefab, Random.Range(0, 3), transform.position + (spawnAngle * transform.forward), transform.rotation * spawnAngle);
            }
            else
            {
                obj = MF_AutoPool.Spawn(spawnPrefab, transform.position + (spawnAngle * transform.forward), transform.rotation * spawnAngle);
            }

            // add some force and some random direction
            Rigidbody rb = null;
            if (obj)
            {
                rb = obj.GetComponent <Rigidbody>();
            }
            if (rb)
            {
                Vector3 myVelocity = myRigidbody ? myRigidbody.velocity : Vector3.zero;
                rb.velocity = myVelocity + (obj.transform.forward * spawnVelocity);
            }

            nextSpawn = Time.time + spawnInterval;
        }
    }
Пример #6
0
 public void Spawn(LeanFinger finger)
 {
     if (finger != null && Prefab != null)
     {
         MF_AutoPool.Spawn(Prefab, finger.GetWorldPosition(FingerDistance), Quaternion.identity);
     }
 }
Пример #7
0
    private void Update()
    {
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, rayRange, mask))
        {
            if (hit.collider.tag == damagingTag)
            {
                if (hit.collider != null)
                {
                    Health hp = hit.collider.gameObject.GetComponent <Health>();
                    if (hp != null)
                    {
                        hp.TakeDamage(damage);
                    }
                }
            }

            if (deathPrefab != null && hit.collider.tag != "Player")
            {
                MF_AutoPool.Spawn(deathPrefab, hit.point, transform.rotation);
                //Instantiate(deathPrefab, hit.point, transform.rotation);
            }

            Kill();
        }
    }
Пример #8
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         //collect the gold and add to gold score
         MF_AutoPool.Despawn(this.gameObject); // this would despawn the gold
     }
 }
Пример #9
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "ball")
     {
         collision.GetComponent <cannonball>().powerup = 10;
         MF_AutoPool.Despawn(collision.gameObject);
     }
 }
Пример #10
0
 public void Spawn()
 {
     Debug.Log("S");
     if (Prefab != null)
     {
         MF_AutoPool.Spawn(Prefab, transform.position, Quaternion.identity);
     }
 }
Пример #11
0
    // Update is called once per frame
    void Update()
    {
        //TIMERS
        //We can create timers using the command Time.deltaTime. This means time that
        //has passed since the last frame (so a constant timer). We can take a float and
        //add or subtract Time.deltaTime to create a timer that counts up or down
        timer -= Time.deltaTime; // -= subtracts time from the timer consistently
        timer += Time.deltaTime; // += adds time to the timer

        if (timer >= 0)
        {
            mybutton.interactable = true; //This allows thwe button to be pressed
        }

        if (timer < 0)
        {
            mybutton.interactable = false; //This greys the button out and cannot be pressed
        }


        Vector3.MoveTowards(start, finish, speed); //This line will move the object
        //The start position is set to the movers position
        //The target position gets set to another gameobject (Usually the player)
        //The speed is constant

        //INSTANTIATE is a way to make things appear in our scene, this could be enemies
        //loot, power ups

        GameObject loot = Instantiate(money, transform.position, transform.rotation);

        //The above line makes a new gameobjects by creating money at our current location
        //We say GameObject loot because we are creating a new gameobject in the hierarchy call loot
        //Money is usually a prefab that we can call over and over again this means money
        //Won't be in the hierarchy but inside the game's asset folder
        Destroy(money, 5f); //This destroys the money if we don't get it fast enough

        //AUTOPOOLING we are using a plugin called Mob Farm Auto Pooler
        GameObject loot2 = MF_AutoPool.Spawn(money, transform.position, transform.rotation);

        //This is the mobile friendly version
        MF_AutoPool.Despawn(this.gameObject, 5f); //This line would be on the money gameobject
        //put it back into the pool without any left over issues

        //ARRAY (How to go through your list and affect each object one at a time)
        //FOR LOOP
        for (int i = 0; i < alltheenemies.Length; i++)


        {
            alltheenemies[i].SetActive(true); //We set each enemy active
        }

        //int i = 0 means we start at the top of the list
        //i < alltheenemies, means as long as the number we are on isn't larger than the list
        //Lets say the list is 10 long, if we are at 0, 0 <10 so we add 1, 1 is less than
        //10  so we add another so on until we get to 10
        //i ++ we move down the list by one
    }
Пример #12
0
    public int GB; // this is just a normal int

    void Start()
    {
        //Player Prefs first we need to create a custom player pref

        PlayerPrefs.SetInt("GreenBird", 2); // this changes the Green Player Pref number to 2
        // this value is remembered between gameplay

        // Next we need to check the player refs
        if (PlayerPrefs.HasKey("GreenBird"))      // Has key checks to see if the player pref exists
        {
            GB = PlayerPrefs.GetInt("GreenBird"); // this is  taking our normal int and setting
            // the same as our player prefs int
        }

        //Finally we need to use the player prefs to make a change

        if (GB == 2)
        {
            myButton.interactable = true; // this makes the green bird button work
        }

        //ARRAY Step 1 Get the list
        alltheenemies = gameObject.FindGameObjectsWithTag("enemy"); // this gets all the gameObjects
        //tagged enemy when the game starts. you can put this line in Update to make the list
        // update in real time

        //ARRAY Step 2 Change objects inside the list
        //FOR LOOP this lets us run through the list and make changes to all the objects on the list
        for (int i = 0; i < alltheenemies.Length; i++) // this line foes through the array untill it gets
        {
            alltheenemies[i].SetActive(false);         // this would turn all the enemies off at once
        }

        // int i = 0 means we start at the top of the list Unity lists start at 0
        // i < alltheenemies.Length this means as long as our current number isn't larger than the whole list
        // so if our list is just 10 we are start at 0 which is lest than 10
        // i++ means we just add one so now we are at 1 which is also less than 10 so we add another
        // now we are at 2 we check again and 2 < 10 so we add another and so on

        StartCoroutine(StartPower());       // this calls the IEnumerator which doesn't run by itself
        // DO NO CALL IEnumerator inside Update
        start  = transform.position;        // this sets out position to the start position
        finish = target.transform.position; // this gets the targets position


        GameObject loot = Instantiate(money, transform.position, transform.rotation);

        // this above line will bring loot into existence at this location and this rotation
        Destroy(money, 5f); // this line gets rid of our instantiated prefab "money"
        // Instantiate and destroy will cause garbage to accumulate so NOT mobile friendly
        //AUTO POOLING
        GameObject loot = MF_AutoPool.Spawn(money, transform.position, transform.rotation);

        MF_AutoPool.Despawn(this.gameObject, 5f); // this line would be on a script on the money
        //gameobject and would despawn it after 5 seconds
    }
Пример #13
0
    IEnumerator Finish()
    {
        mo.enabled = true;
        anim.SetBool("fall", false);
        hit = false;
        transform.position = start.position;
        yield return(new WaitForSeconds(.01f));

        MF_AutoPool.Despawn(mover);
    }
Пример #14
0
 void DoDestroy()
 {
     if (poolRefScript)
     {
         MF_AutoPool.Despawn(poolRefScript);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Пример #15
0
 void Start()
 {
     for (int i = 0; i < spawnTypes.Length; i++)
     {
         if (spawnTypes[i].objectPool == true)
         {
             MF_AutoPool.InitializeSpawn(spawnTypes[i].prefab, spawnTypes[i].addPool, spawnTypes[i].minPool);
         }
     }
     Spawn(beginAmount);
 }
Пример #16
0
    public void SpawnAgain()
    {
        Vector3 spawnPosition2 = new Vector3();

        for (int i = 0; i < numberOfPlatforms; i++)
        {
            spawnPosition2.y += (player.transform.position.y + Random.Range(minY, maxY));
            spawnPosition2.x  = Random.Range(-levelWidth, levelWidth);
            MF_AutoPool.Spawn(platformPrefab, spawnPosition2, Quaternion.identity);
        }
    }
Пример #17
0
    // Update is called once per frame
    void Update()
    {
        //TIMERS
        //we can create timers using command Time.deltaTime
        //This is the time that has past since the last frame (so a constant timer)
        //we can take a float and add or subtract Time.deltaTime that counts up or down
        timer -= Time.deltaTime; //-= subtracts time from timer, += adds time to timer

        if (timer >= 0)
        {
            mybutton.interactable = true; //allows button to be pressed
        }

        if (timer < 0)
        {
            mybutton.interactable = false; //this grays out button and it cannot be pressed
        }

        Vector3.MoveTowards(start, finish, speed); //this line will move the object
        //start position set to movers position
        //target position gets set to another GameObject (such as the player)
        //speed is constant


        //INSTANTIATE is a way to make objects appear in our scene, this could be enemies, loot, power ups

        GameObject loot = Instantiate(money, transform.position, transform.rotation);

        //Above code creates money at our currant location
        //we say GameObject loot to create a new GameObject in the hierarchy called loot
        //Money is usually a prefab that we can call over and over again
        //this means money won't be in the heirarchy but inside the game's asset folder
        Destroy(money, 5f); //destroys the money we don't pick up fast enough

        //AUTOPOOLING
        //we are using a plugin called Mob FArm Auto Pooler
        GameObject loot2 = MF_AutoPool.Spawn(money, transform.position, transform.rotation);

        //mobile friendly version
        MF_AutoPool.Despawn(this.gameObject, 5f); //this would take the money away and add it back to the pool
                                                  //line is on money itself

        //ARRAY
        //How to go thro your list and affect each object one at a time
        //FOR LOOP
        for (int i = 0; i < alltheenemies.Length; i++)
        {
            alltheenemies[i].SetActive(true); //we set all the enemies as active
        }
// int i = 0 means we start at the top of the list
// i < allenemies, means as long as the number we're on isn't larger than the list i++
//we move down the list by 1, starting at 0 (list is 10 long, we add 1 until we get to 10)
    }
Пример #18
0
 public override void Awake()
 {
     if (error == true)
     {
         return;
     }
     base.Awake();
     if (objectPool == true)
     {
         MF_AutoPool.InitializeSpawn(shot.gameObject, addToPool, minPool);
     }
 }
Пример #19
0
    void Awake()
    {
        MF_AutoPool.InitializeSpawn(startPlatformPrefab, 1, 100);
        MF_AutoPool.InitializeSpawn(middlePlatformPrefab, 1, 100);
        MF_AutoPool.InitializeSpawn(endPlatfromPrefab, 1, 100);
        MF_AutoPool.InitializeSpawn(movingPlatformPrefab, 4, 100);
        for (int i = 0; i < obstacles.Count; i++)
        {
            MF_AutoPool.InitializeSpawn(obstacles[i], 1, 50);
        }

        levelfinishScreen = gameCanvas.transform.Find("LevelFinishButton").GetComponent <Button>();
    }
Пример #20
0
    void Update()
    {
        // check if time to die
        if (didDeath == false && Time.time >= startTime + deathTime)
        {
            if (myRigidbody)
            {
                myRigidbody.isKinematic = true;
            }
            // swap states of objects to show blast and hide object
            if (enabledObject)
            {
                enabledObject.SetActive(false);
            }
            if (disabledObject)
            {
                disabledObject.SetActive(true);
            }
            for (int i = 0; i < version.Length; i++)
            {
                if (version[i])
                {
                    version[i].SetActive(false);
                }
            }
            didDeath = true;
        }
        // check if time to despawn
        if (Time.time >= startTime + deathTime + despawnTime)
        {
            if (refScript)
            {
                if (MF_AutoPool.Despawn(refScript) == false)
                {
                    // if object couldn't be despawned, then destroy it
                    Destroy(gameObject);
                }
                // Alternately, we could use:

                // MF_AutoPool.Despawn( gameObject );

                // and not have to bother with initializing AP_Reference at all,
                // but using gameObject is a little slower, since internally it uses GetComponent<MF_AutoPoolreference>() to find the script
            }
            else
            {
                // no refScript found
                Destroy(gameObject);
            }
        }
    }
    protected void FireProjectile()
    {
        Vector3 dir = spawner.transform.forward;

        dir += spawner.transform.right * Random.Range(-coneSize, coneSize);
        dir += spawner.transform.up * Random.Range(-coneSize, coneSize);

        Bullet instance = MF_AutoPool.Spawn(projectilePrefab, spawner.position, spawner.transform.rotation).GetComponent <Bullet>();

        //Bullet instance = Instantiate(projectilePrefab, spawner.position, spawner.transform.rotation);
        instance.Init(damage, dir.normalized * projectileForce);

        PlaySound();
    }
Пример #22
0
    public void SpawnCoolGuy()
    {
        MF_AutoPool.InitializeSpawn(coolguy, 1, 50);

        coolguyOnGame = MF_AutoPool.Spawn(coolguy);

        coolguyOnGame.transform.position = new Vector3(0, 5, 1);
        coolguyOnGame.transform.parent   = transform;
        CameraControl();
        animatorController = coolguyOnGame.GetComponent <Animator>();
        StartCoroutine("HoldNavAgent");

        isFinish = false;
    }
Пример #23
0
    void Start()
    {
        MF_AutoPool.InitializeSpawn(coolguy, 1, 50);

        //events for character control
        CoolGuy.CollisionTypeSnd  += null;
        LevelBuilder.onCoolGuySpa += null;
        LevelBuilder.onCoolGuySpa += SpawnCoolGuy;
        CoolGuy.CollisionTypeSnd  += CollisionBehaviour;
        CoolGuy.CollisionCountSnd += GameFailedFromFallPlatform;


        lifeAmountText.text = "lifeAmount : " + lifeAmount.ToString();
    }
Пример #24
0
    IEnumerator SpawnEnemies()
    {
        while (true)
        {
            float delay = Random.Range(minDelay, maxDelay);
            yield return(new WaitForSeconds(delay));

            int       spawnIndex = Random.Range(0, spawnPoints.Length);
            Transform spawnPoint = spawnPoints[spawnIndex];

            GameObject senemy = MF_AutoPool.Spawn(enemy, spawnPoint.position, spawnPoint.rotation);
            //Destroy(senemy, 5f);
        }
    }
Пример #25
0
    void SpawnPlatformandObstacle(GameObject platformPrefab, bool isObstacle)
    {
        GameObject singleplatform = MF_AutoPool.Spawn(platformPrefab);

        singleplatform.transform.parent   = this.transform;
        singleplatform.transform.position = Vector3.zero;

        singleplatform.transform.position = new Vector3(singleplatform.transform.position.x, singleplatform.transform.position.y, (singleplatform.transform.localScale.z / 2) + iterationValuePlatform);

        if (!isObstacle)
        {
            iterationValuePlatform = IterationPositionValue(singleplatform);
        }
    }
Пример #26
0
 public virtual void DoDestroy()
 {
     // destroy or despawn object
     if (poolRefScript == null || MF_AutoPool.Despawn(poolRefScript) == false)
     {
         if (transform.parent != null)                 // part of larger object
         {
             gameObject.SetActive(false);
         }
         else
         {
             Destroy(gameObject);
         }
     }
 }
Пример #27
0
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Player")
     {
         powerup = 10;
         MF_AutoPool.Despawn(this.gameObject);
         mm.goldCount += 1;
         goldsound.Play();
         //ev.money += 1;
     }
     if (collision.tag == "Catcher")
     {
         powerup = 10;
         MF_AutoPool.Despawn(this.gameObject);
     }
 }
Пример #28
0
    // Update is called once per frame
    void Update()
    {
        if (up == true)
        {
            myRB2d.velocity = new Vector2(0, jetpower);
        }

        else
        {
            myRB2d.velocity = new Vector2(0, 0);
        }

        if (CnInputManager.GetButtonDown("Shoot"))
        {
            MF_AutoPool.Spawn(cannonball, transform.position, transform.rotation);
            cannonball.GetComponent <cannonball>().powerup = 10;
        }
    }
Пример #29
0
    public void SpawnCoolGuy()
    {
        coolguyOnGame = MF_AutoPool.Spawn(coolguy);

        coolguyOnGame.transform.position = new Vector3(0, 3, 1);
        coolguyOnGame.transform.parent   = transform;
        animatorController = coolguyOnGame.GetComponent <Animator>();

        CameraControl();
        //getting collider for ragdoll
        mainCollider = coolguyOnGame.transform.GetComponent <Collider>();
        allColliders = coolguyOnGame.transform.GetChild(0).GetComponentsInChildren <Collider>(true);

        //holding start position
        holdStartPos = coolguyOnGame.transform.position;

        DoRagdoll(false);
    }
Пример #30
0
    public override void DoFire(Transform target)
    {
        if (error == true)
        {
            return;
        }
        if (active == false)
        {
            return;
        }

        // fire weapon
        // create shot
        GameObject myShot = null;

        for (int spr = 0; spr < shotsPerRound; spr++)
        {
            if (objectPool == true)
            {
                myShot = MF_AutoPool.Spawn(shot.gameObject, exits[curExit].transform.position, exits[curExit].transform.rotation);
            }
            else
            {
                myShot = (GameObject)Instantiate(shot.gameObject, exits[curExit].transform.position, exits[curExit].transform.rotation);
            }
            if (myShot != null)
            {
                Vector2 errorV2 = Random.insideUnitCircle * curInaccuracy;
                myShot.transform.rotation *= Quaternion.Euler(errorV2.x, errorV2.y, 0);
                Rigidbody _rb = myShot.GetComponent <Rigidbody>();
                _rb.velocity   = platformVelocity + (myShot.transform.forward * shotSpeed);
                _rb.useGravity = usingGravity;
                MF_B_Projectile shotScript = myShot.GetComponent <MF_B_Projectile>();
                shotScript.duration = shotDuration;
            }
        }
        if (myShot != null)             // at least one shot was created
        {
            base.DoFire(target);
        }
    }