Exemplo n.º 1
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag == "Apple")
        {
            GoldenApple apple = collision.gameObject.GetComponentInParent <GoldenApple>();
            switch (apple.Type)
            {
            case AppleType.Golden:
                DeltaSpeed -= ChangeSpeed;
                Invoke(nameof(Speedtime), 5);
                break;

            case AppleType.Blue:
                Light2D SnakeLight = GetComponentInChildren <Light2D>();
                Invoke(nameof(SnakeVisionRadius), 10);
                SnakeLight.pointLightOuterRadius += 9;
                break;
            }

            GameObject.Destroy(collision.gameObject, 0.15f);
            result++;

            Score.text = "Score: " + result;
            IsApple    = true;
            AppleController.CreateApple();

            BodyCreate();
            SnakeEat.SetTrigger("Eat");
            return;
        }
        if (collision.tag == "Spikes" || collision.tag == "body" || collision.tag == "Enemy")
        {
            Dead();
        }
    }
Exemplo n.º 2
0
    void AppleCreate()
    {
        Vector3 P = Vector3.zero;

        P.x = Random.Range(PlayArea.bounds.min.x, PlayArea.bounds.max.x);
        P.y = Random.Range(PlayArea.bounds.min.y, PlayArea.bounds.max.y);
        GoldenApple apple  = Instantiate(Apple, P, Quaternion.identity);
        float       random = Random.value;

        if (random < 0.15f)
        {
            apple.Type = AppleType.Golden;
        }
        else if (random < 0.20f)
        {
            apple.Type = AppleType.Blue;
        }
        else
        {
            apple.Type = AppleType.Normal;
        }
    }