Exemplo n.º 1
0
    bool firstFall;                                                                                                          // is this the first loop where the duck is falling?

    void Start()
    {
        audioManager = AudioManager.instance;   // set up singletons
        duckBoundary = DuckBoundary.instance;

        animator = GetComponent <Animator>();
        rb       = GetComponent <Rigidbody2D>(); // access the various components
        hitbox   = GetComponent <Hitbox>();

        fallSound.InitializeAudioSource(gameObject.AddComponent <AudioSource>()); // initialize the fall sound

        speed     = Random.Range(minSpeed, maxSpeed);                             // generate a random speed for the duck
        direction = directions[Random.Range(0, directions.Length)];               // set the duck's direction to one of the 4 defined above

        firstFall = true;                                                         // the duck hasn't fallen yet, so the next fall will certainly be it's first

        if (direction.x < 0)
        {                          // the animator defaults to the animation "Fly1", which faces right. if the x direction is negative,
            animator.Play("Fly2"); // the duck will be flying left, so we have to play "FLy2", an animation that faces left
        }

        rb.velocity = direction * speed; // set the physics velocity to the duck's directional vector multiplied by the duck's speed

        duckState = DuckState.alive;     // make sure the duck is alive
    }
Exemplo n.º 2
0
    private void Awake()
    {
        if (instance != null)
        {
            Debug.LogWarning("Multiple instances of " + this + "found");
        }

        instance = this;

        boundary = new Boundary(scale, offset); // calculates the duck x's & y's min and max
    }