Exemple #1
0
 // Update is called once per frame
 void Update()
 {
     if (cs.getMode() == 2)
     {
         powerUpTimer -= Time.deltaTime;
         //print(powerUpTimer);
         if (powerUpTimer <= 0)
         {
             cs.setMode(1); // Set the mode back to just grown
             cs.multiplier    = 1;
             cs.numberOfJumps = 2;
             enemySpeed       = 1f;
         }
     }
 }
    void PowerUp()
    {
        if (sb.getMode() == 0)
        {
            p_up = (GameObject)Instantiate(Resources.Load("PowerUpGrow", typeof(GameObject)));
        }
        else if (sb.getMode() == 1 || sb.getMode() == 2) // 2 means we are already powered up but we can get a coin multiplier if we get another powerup
        {
            System.Random rand    = new System.Random();
            int           powerUp = rand.Next(2, 5); // max value is exclusive

            //print(powerUp);
            if (powerUp == 2)
            {
                p_up = (GameObject)Instantiate(Resources.Load("PowerUpFire", typeof(GameObject)));
            }
            else if (powerUp == 3)
            {
                p_up = (GameObject)Instantiate(Resources.Load("PowerUpFly", typeof(GameObject)));
            }
            else if (powerUp == 4)
            {
                p_up = (GameObject)Instantiate(Resources.Load("PowerUpTimeWarp", typeof(GameObject)));
            }
        }

        p_up.transform.SetParent(this.transform.parent);
        p_up.transform.localPosition = new Vector2(position.x, position.y + 1);

        rb = p_up.GetComponent <Rigidbody2D>();
        cc = p_up.GetComponent <CircleCollider2D>();

        powerUpExists = true;

        this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("G2-block-hit");
    }