private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     //Standing on last ground -> wait for touch and turn
     if (hit.collider.CompareTag("LastGround") && hit.collider.gameObject != currentLastGround)
     {
         currentLastGround        = hit.collider.gameObject;
         currentLastGroundControl = hit.collider.GetComponent <LastGroundController>();
         touchDisable             = true;
         StartCoroutine(WaitForTouch());
     }
     else if (hit.collider.CompareTag("SpeedDownTrap")) //Reduce moving speed
     {
         movingSpeed = minMovingSpeed;
         jumpForce   = minJumpForce;
     }
     else if (listDeadTag.Contains(hit.collider.tag)) //Dead tag -> game over
     {
         if (hit.collider.CompareTag("FireTrap"))
         {
             GameObject par = Instantiate(gameManager.firedParticle, transform.position, Quaternion.identity);
             par.transform.eulerAngles = new Vector3(-90, 0, 0);
             foreach (Renderer o in transform.GetComponentsInChildren <Renderer>())
             {
                 o.material.SetFloat("_Metallic", 1);
             }
             PlayParticle(par.GetComponent <ParticleSystem>());
         }
         if (hit.collider.CompareTag("IceTrap"))
         {
             GameObject par = Instantiate(gameManager.freezingParticle, transform.position, Quaternion.identity);
             par.transform.SetParent(transform);
             anim.enabled = false;
             PlayParticle(par.transform.GetChild(0).GetComponent <ParticleSystem>());
         }
         if (hit.collider.CompareTag("ThornTrap"))
         {
             hit.gameObject.GetComponent <ThornTrapController>().GoUp();
         }
         GameOver();
         PushPlayerAway(hit.collider.transform.position);
     }
     else //Nornal ground
     {
         movingSpeed = maxMovingSpeed;
         jumpForce   = maxJumpForce;
         if (hit.collider.CompareTag("Stair"))
         {
             Ray        ray = new Ray(hit.transform.position, movingDirection);
             RaycastHit rayCastHit;
             if (Physics.Raycast(ray, out rayCastHit, 20f))
             {
                 yCheckPos = rayCastHit.collider.transform.position.y + factor;
             }
         }
         else
         {
             yCheckPos = hit.transform.position.y + factor;
         }
     }
 }
    void Start()
    {
        //        // Uncomment to enable changing the character to the selected one
        GameObject currentCharacter = CharacterManager.Instance.characters[CharacterManager.Instance.CurrentCharacterIndex];
        Material   charMaterial     = currentCharacter.transform.GetChild(0).GetComponent <Renderer>().sharedMaterial;

        //Get the mesh
        Mesh charMainMesh      = currentCharacter.transform.Find("Main").GetComponent <MeshFilter>().sharedMesh;
        Mesh charLeftHandMesh  = currentCharacter.transform.Find("LeftHand").GetComponent <MeshFilter>().sharedMesh;
        Mesh charRightHandMesh = currentCharacter.transform.Find("RightHand").GetComponent <MeshFilter>().sharedMesh;
        Mesh charLeftFootMesh  = currentCharacter.transform.Find("LeftFoot").GetComponent <MeshFilter>().sharedMesh;
        Mesh charRightFootMesh = currentCharacter.transform.Find("RightFoot").GetComponent <MeshFilter>().sharedMesh;

        //Change player's child mesh to the selected character
        main.GetComponent <MeshFilter>().mesh        = charMainMesh;
        leftHand.GetComponent <MeshFilter>().mesh    = charLeftHandMesh;
        rightHand.GetComponent <MeshFilter>().mesh   = charRightHandMesh;
        leftFoot.GetComponent <MeshFilter>().mesh    = charLeftFootMesh;
        rightFoot.GetComponent <MeshFilter>().mesh   = charRightFootMesh;
        main.GetComponent <Renderer>().material      = charMaterial;
        leftHand.GetComponent <Renderer>().material  = charMaterial;
        rightHand.GetComponent <Renderer>().material = charMaterial;
        leftFoot.GetComponent <Renderer>().material  = charMaterial;
        rightFoot.GetComponent <Renderer>().material = charMaterial;

        charControl = GetComponent <CharacterController>();
        rigid       = GetComponent <Rigidbody>();
        anim        = GetComponent <Animator>();
        currentLastGroundControl = null;
        movingDirection          = Vector3.forward;
        touchDisable             = false;
        isDead      = false;
        movingSpeed = maxMovingSpeed;
        jumpForce   = maxJumpForce;
        factor      = gameManager.groundPrefab.GetComponent <Renderer>().bounds.size.y - 0.2f;

        yCheckPos = gameManager.firstGround.transform.position.y + factor;

        //Add dead tag
        listDeadTag.Add("ThornTrap");
        listDeadTag.Add("Saw");
        listDeadTag.Add("IceTrap");
        listDeadTag.Add("FireTrap");
        listDeadTag.Add("Bullet");
        listDeadTag.Add("Obstacle");
    }