Inheritance: MonoBehaviour
Example #1
0
    void SpawnBird(bool isForeground = false)
    {
        Vector3 spawnPos;

        Collider[] hitColliders;
        if (isForeground) // Spawn bird in foreground
        {
            int i = 0;
            do
            {
                spawnPos = GetRandomPointInGameArea();
                i++;
                hitColliders = Physics.OverlapSphere(spawnPos, 2f, overlapCheckLayerMask); // Don't spawn on top of another bird or tree
            } while (hitColliders.Length > 0 && i < 30);                                   // Failsafe in case game is set up too crowded
        }
        else // Spawn bird in background
        {
            spawnPos = GetRandomPointInBackground();
        }

        GameObject    newBird   = Instantiate(GetRandomBird(), spawnPos, Quaternion.identity);
        BirdBehaviour behaviour = newBird.GetComponent <BirdBehaviour>();

        behaviour.Initialize(this, isForeground);

        if (isForeground)   // Keep track of the birds, so when one dies, we can send some from the background to the main game area.
        {
            foregroundBirds.Add(behaviour);
        }
        else
        {
            backgroundBirds.Add(behaviour);
        }
    }
Example #2
0
 void Awake()
 {
     if (instance = null)
     {
         instance = this;
     }
     spriteRenderer = GetComponent <SpriteRenderer>();
 }
Example #3
0
 public void OnTriggerEnter2D(Collider2D other)
 {
     if ((Caught == null) && ReadyToCatch)
     {
         var bird = other.GetComponent <BirdBehaviour>();
         if (bird != null)
         {
             bird.CaughtBy = this;
             Caught        = bird;
         }
     }
 }
Example #4
0
    private IEnumerator CreateObstacle()
    {
        float newWait = 0.0f;

        for (;;)
        {
            int rnd = Random.Range(1, 100);
            // print(rnd);
            foreach (Obstacles obs in System.Enum.GetValues(typeof(Obstacles)))
            {
                if (rnd < (int)obs)
                {
                    switch (obs)
                    {
                    case Obstacles.Bubble:
                        BubbleBehaviour.Spawn(baseBubble, spawnBubbleVelocity, this.transform.position);
                        newWait = 0.0f;
                        break;

                    case Obstacles.Floater:
                        FloaterBehaviour.Spawn(baseFloater, spawnFloaterVelocity, this.transform.position);
                        newWait = 0.0f;
                        break;

                    case Obstacles.Bird:
                        Vector2 pos = new Vector2(this.transform.position.x, this.transform.position.y + Random.Range(1.3f, 3f));
                        BirdBehaviour.Spawn(baseBird, spawnBirdVelocity, pos);
                        break;

                    default:
                        timeNone += newWait;
                        if (timeNone > maxTimeNone)
                        {
                            BubbleBehaviour.Spawn(baseBubble, spawnBubbleVelocity, this.transform.position);
                        }
                        break;
                    }
                    break;
                }
            }

            newWait = Random.Range(randomWait_min, randomWait_max);
            yield return(new WaitForSeconds(newWait));
        }
    }
Example #5
0
 private void Awake()
 {
     _birdBehaviour = GetComponent <BirdBehaviour>();
 }
 void Start()
 {
     _birdBehaviour = GetComponent <BirdBehaviour>();
     _birdMovement  = GetComponent <BirdMovement>();
 }
Example #7
0
 private void Awake()
 {
     _rigidbody2D   = GetComponent <Rigidbody2D>();
     _birdBehaviour = GetComponent <BirdBehaviour>();
 }
 private void Start()
 {
     behaviour = GetComponent <BirdBehaviour>();
 }
 private void Start()
 {
     behaviour = GetComponent <BirdBehaviour>();
     // fly towards the South position at the start of the game
     behaviour.ChangeTarget(behaviour.GetSouthPosition().position);
 }