예제 #1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        GameObject other = collision.gameObject;

        if (other.GetComponent <PlayerController>() != null)
        {
            if (FindObjectsOfType <EnemyController>().Length > 0)
            {
                Debug.Log("Enemies remain");
            }
            else
            {
                Debug.Log("Good job ur done the level");
                WinBattle win = FindObjectOfType <WinBattle>();
                if (win != null)
                {
                    win.Win();
                }
                else
                {
                    Debug.LogError("No object with WinBattle behaviour");
                }
                GameState state = FindObjectOfType <GameState>();
                if (state != null)
                {
                    state.AddGold(500);
                    state.AddCrew();
                }
                else
                {
                    Debug.LogError("No object with GameState behaviour");
                }
            }
        }
    }
예제 #2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        ActorController other = collision.gameObject.GetComponent <ActorController>();

        // If the target is an enemy and is killed, give the player gold
        int             goldValue = 0;
        EnemyController enemy     = collision.gameObject.GetComponent <EnemyController>();

        if (enemy != null)
        {
            goldValue = enemy.goldValue;
        }

        if (other != null && !holder.GetActorsHitThisFrame().Contains(other))
        {
            // Someone important got hit!
            Debug.Log(collision.gameObject.name + " got smacked by " + holder.name);
            other.TakeDamage(damage);
            holder.GetActorsHitThisFrame().Add(other);

            if (other.IsAlive())
            {
                // they survived the hit
                // Knock them back
                Rigidbody2D rb = collision.gameObject.GetComponent <Rigidbody2D>();

                // Sometimes collision.contacts.Length == 0 for some reason - need to investigate
                // Collision.contacts documentation says should always be at least 1

                /*
                 * if (collision.contacts.Length > 0 &&
                 *  collision.contacts[0].point.x > collision.otherCollider.bounds.center.x) {*/
                if (holder.transform.position.x < other.transform.position.x)
                {
                    //Debug.Log("Knocking back positive");
                    rb.AddForce(new Vector2(hKnockback, vKnockback));
                }
                else
                {
                    //Debug.Log("Knocking back negative");
                    rb.AddForce(new Vector2(-hKnockback, vKnockback));
                }
            }
            else
            {
                // The target died
                if (goldValue != 0)
                {
                    GameState state = FindObjectOfType <GameState>();
                    if (state != null)
                    {
                        state.AddGold(enemy.goldValue);
                    }
                }
            }
        }
    }
예제 #3
0
    public IEnumerator WinCoroutine()
    {
        while (fadeImage.color.a < 0.8f)
        {
            fadeImage.color      = new Color(fadeImage.color.r, fadeImage.color.g, fadeImage.color.b, fadeImage.color.a + Time.deltaTime);
            music.volume        -= Time.deltaTime;
            ambientSound.volume -= Time.deltaTime;
            yield return(null);
        }

        music.volume        = 0f;
        ambientSound.volume = 0f;
        music.Stop();
        ambientSound.Stop();

        yield return(new WaitForSeconds(0.3f));

        buttonSound.Play();
        textPanel.SetActive(true);

        yield return(new WaitForSeconds(0.5f));

        buttonSound.Play();
        button.SetActive(true);

        yield return(new WaitForSeconds(0.3f));

        music.clip   = winMusic;
        music.volume = 0.5f;
        music.Play();

        GameState g = FindObjectOfType <GameState>();

        if (g != null)
        {
            // Win, get some gold
            g.AddGold(1000);
        }

        yield return(null);
    }