Example #1
0
    [SerializeField] public int typeOfAnimal; //whichever class we want to use, the Bunny: bunny class or Cat: Bunny class

    // Start is called before the first frame update
    void Start()
    {
        i    = SydneyIterate.first();        //set i to first of the iterator
        objs = new GameObject[numOfObjects]; //an array of new gameobjects (obj)
        //which particle type do we want to use (1 for Bunny, 2 for Cat)
        if (typeOfAnimal == 1)
        {
            c1 = new Bunny(); //super class
        }
        else if (typeOfAnimal == 2)
        {
            c1 = new Cat(); //sub class
        }
    }
Example #2
0
    //all child classes will contain isSpawn since it is virtual
    //function creates random value between 1 and spawnspeed,
    //if value is under 2f, and we are not out of objects (based on iterators isDone),
    //spawn the object
    virtual public bool isSpawn(int numOfObjects, float spawnSpeed)
    {
        float poss;

        poss = Random.Range(1f, spawnSpeed);
        if (poss <= 2f && !SydneyIterate.isDone(numOfObjects))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        //both Bunny and Cat have a function isSpawn, but is only declared in the Bunny class.
        //Cat inherits this function since it is virtual. isSpawn is a random number generator
        //to determine if we should spawn the object yet or not.
        if (c1.isSpawn(numOfObjects, spawnSpeed))
        {
            //rand is a random value on the x-axis to make the particle fall more natural
            randx = Random.Range(0, 16);
            randy = Random.Range(0, 16);

            //instantiate whatever object we are at in the iterator
            objs[i] = Instantiate(obj, new Vector2(randx, randy), transform.rotation);
            //cat has a different spawnBun function than bunny, so it is static in bunny
            //spawnBun either makes the sprite spawned a bunny or a cat
            c1.spawnBun(objs[i]);
            //use the iterator next function
            i = SydneyIterate.next();
        }
    }