Esempio n. 1
0
    [SerializeField] public int typeOfParticle; //whichever class we want to use, the Snow: Snow class or Confetti: Snow clas

    // Start is called before the first frame update
    void Start()
    {
        j    = RonnieIterate.first();        //set j 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 snow, 2 for confetti)
        if (typeOfParticle == 1)
        {
            particleClass = new Snow(); //super class
        }
        else if (typeOfParticle == 2)
        {
            particleClass = new Confetti(); //sub class
        }
    }
Esempio n. 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
    //public static bool isSpawn(int numOfObjects, float spawnSpeed) { //in the case I need a static type here (change Particles.cs line 42 to comment line 41)
    public virtual bool isSpawn(int numOfObjects, float spawnSpeed)
    {
        float poss;

        poss = Random.Range(1f, spawnSpeed);
        if (poss <= 2f && !RonnieIterate.isDone(numOfObjects))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 3
0
 // Update is called once per frame
 void Update()
 {
     //both snow and confetti have a function isSpawn, but is only declared in the snow class.
     //confetti 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(Snow.isSpawn(numOfObjects, spawnSpeed)) { //in the case that I need a static type in the snow Class
     if (particleClass.isSpawn(numOfObjects, spawnSpeed))
     {
         //rand is a random value on the x-axis to make the particle fall more natural
         rand = Random.Range(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)).x, Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0)).x);
         //instantiate whatever object we are at in the iterator
         objs[j] = Instantiate(obj, new Vector2(rand, Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height)).y), transform.rotation);
         //confetti has a different changeColor function than snow, so it is static in snow
         //change color either makes the particle white or gives it a random color (limited to 5 colors, still looks like confetti)
         particleClass.changeColor(objs[j]);
         //use the iterator next function
         j = RonnieIterate.next();
     }
 }