Esempio n. 1
0
 void CreateObject(float randomTime, int randomPowerup)
 {
     GameObject instance = Instantiate((Object)power_up_prefabs[randomPowerup]) as GameObject;
     PositionHelper ph = new PositionHelper();
     Vector3 position = ph.GenerateStartingPosition();
     instance.transform.position = position;
     instance.transform.localScale += new Vector3(1, 1, 1);
     instance.AddComponent<Rigidbody2D>();
     instance.AddComponent<CircleCollider2D>();
     CircleCollider2D cc = instance.GetComponent<CircleCollider2D>();
     cc.isTrigger = true;
     Rigidbody2D rb = instance.GetComponent<Rigidbody2D>();
     rb.gravityScale = 0;
     rb.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation;
     rb.AddForce(new Vector3(0f, 150f, 0f));
     power_ups.Add(instance);
     Invoke("InitializeObject", randomTime);
 }
Esempio n. 2
0
 void MoveWall()
 {
     foreach(GameObject wall_parent in wall_parents)
     {
         Wall wall = wall_parent.GetComponentInChildren<Wall>();
         if (!wall.IsMoving)
         {
             Rigidbody2D rb = wall_parent.GetComponent<Rigidbody2D>();
             PositionHelper ph = new PositionHelper();
             Vector3 position = ph.GenerateStartingPosition();
             wall_parent.transform.position = position;
             rb.velocity = new Vector3();
             wall.ScaleWall(position);
             wall.IsMoving = true;
             rb.AddForce(new Vector3(0f, 100f, 0f));
             GameObject instance = Instantiate(spike) as GameObject;
             instance.name = "SpikeBase";
             instance.transform.SetParent(wall_parent.transform, false);
             break;
         }
     }
 }