void SetGroundAttribute(GameObject obj)
    {
        // Random Type
        GroundScript.GroundType groundType = (GroundScript.GroundType)Random.Range(0, 3);
        float   velocity = 0;
        Vector2 newScale = new Vector2(groundWidth, groundHeight);

        if (groundType == GroundScript.GroundType.Normal)
        {
            velocity = Random.Range(minVelocity, maxVelocity);
            newScale = new Vector2(groundWidth, groundHeight);
        }
        else if (groundType == GroundScript.GroundType.JumpHigh)
        {
            velocity = Random.Range(minVelocity, maxVelocity);
            obj.GetComponent <GroundScript>().SetColor(10, 10, 10);
            newScale = new Vector2(groundWidth * 0.8f, groundHeight * 0.75f);
        }
        else if (groundType == GroundScript.GroundType.TimeBomb)
        {
            velocity = Random.Range(minVelocity * 1.25f, maxVelocity * 1.25f);
            newScale = new Vector2(groundWidth, groundHeight);
        }

        obj.GetComponent <GroundScript>().SetGround(newScale, 0, 0, velocity, groundType);
    }
Esempio n. 2
0
    void OnCollisionEnter2D(Collision2D target)
    {
        // Get Standing Groud Type
        GroundScript groundScriptComponent = target.gameObject.GetComponent <GroundScript>();

        standingGroundType = groundScriptComponent.groundType;

        rigidBody2DComponent.velocity = Vector2.zero;
        currentPlayerState            = PlayerState.Standing;
        transform.SetParent(target.gameObject.transform);
        GetPreviousPositionOfParent();
        if (initialCollide == false)
        {
            if (groundScriptComponent.GetStepped() == false)
            {
                groundScriptComponent.Stepped();
                GameObject.Find("_ScoreManager").GetComponent <ScoreManagerScript>().AddScore();
            }

            GameObject.Find("_AudioManager").GetComponent <AudioManagerScript>().PlayCoinSound();
            StartCoroutine(target.gameObject.GetComponent <GroundScript>().LandingEffect());
            GameObject landingEffect = Instantiate(landingEffectPrefab, transform.position, Quaternion.identity);
            Destroy(landingEffect, 0.1f);
        }
        else
        {
            initialCollide = false;
        }
    }
    void OnCollisionEnter2D(Collision2D target)
    {
        GroundScript groundScriptComponent = target.gameObject.GetComponent <GroundScript>();

        if (groundScriptComponent == null)
        {
            return;
        }

        if (transform.position.y <= target.transform.position.y + 1)
        {
            return;
        }

        SetPositionIntoParentBound(target.transform);
        // Get Standing Groud Type
        standingGroundType = groundScriptComponent.groundType;

        rigidBody2DComponent.velocity     = Vector2.zero;
        rigidBody2DComponent.gravityScale = 0;
        currentPlayerState = PlayerState.Standing;
        animatorComponent.SetBool("Jumping", false);
        transform.SetParent(target.gameObject.transform);

        GetPreviousPositionOfParent();
        if (initialCollide == false)
        {
            if (groundScriptComponent.GetStepped() == false)
            {
                // if (groundScriptComponent.groundType == GroundScript.GroundType.Shoe) { jsGM.AddScore(true); Destroy(groundScriptComponent.transform.GetChild(0).gameObject);  }
                // if (groundScriptComponent.groundType == GroundScript.GroundType.Shoe) { jsGM.AddScore(true); }
                //  else jsGM.AddScore();
                jsGM.AddScore();
                groundScriptComponent.Stepped();
                GameObject landingEffect = Instantiate(landingEffectPrefab, transform.position, Quaternion.identity);
                Destroy(landingEffect, 0.2f);

                // play circle burst
                landingEffectPrefab2.Play();
            }

            StartCoroutine(target.gameObject.GetComponent <GroundScript>().LandingEffect());
        }
        else
        {
            initialCollide = false;
        }
    }