Example #1
0
 void OnCollisionEnter(Collision collision)
 {
     if (collision.transform.tag == "Platform")
     {
         OncomingPlatforms.SortPlats();
         gameManager.PlaySound(10, 3, collision.transform.position);
         //Debug.Log("Player is grounded");
         transform.SetParent(collision.transform);
         transform.SetAsFirstSibling();
         isGrounded = true;
     }
 }
Example #2
0
    void Update()
    {
        bool up    = Input.GetButton("Up");
        bool left  = Input.GetButton("Left");
        bool right = Input.GetButton("Right");

        float horz = Input.GetAxis("Horizontal");
        float vert = Input.GetAxis("Vertical");

        if ((up || left || right) && isGrounded)
        {
            gameManager.PlaySound(11, 5f, this.transform.position);
            startPos = transform.position;
            int platformIndex;
            if (right)
            {
                platformIndex = 2;
            }
            else if (left)
            {
                platformIndex = 0;
            }
            else
            {
                platformIndex = 1;
            }

            if (OncomingPlatforms.sortedPlats[platformIndex] != null)
            {
                Debug.Log("Jumping to " + platformIndex);
                targetObj = OncomingPlatforms.sortedPlats[platformIndex];
            }
            else
            {
                Debug.Log("Jumping into space");
                targetObj = null;
                transform.SetParent(transform.parent.parent);
                targetPos = new Vector3(transform.position.x + (18f - platSpeed * decreaseJumpBySpeed),
                                        transform.position.y,
                                        transform.position.z + (5 - (5 * platformIndex)));
            }

            height           = 0;
            verticalVelocity = jumpPower;
            curTime          = 0;
            isGrounded       = false;
            OncomingPlatforms.ClearNext();

            //    hasPeaked = false;
            //    isGrounded = false;
            //    Debug.Log("Jumping...");
            //    initialHeight = transform.position.y;
            //    Jump();
            //}
            //else if (!isGrounded && Input.GetButtonDown("Jump"))
            //{
            //    hasPeaked = true;
            //    //Jump();
            //}
            //else if (!isGrounded)
            //{
            //   // Jump();
            //}
        }

        //Restart game if player falls
        if (transform.position.y < restartHeight)
        {
            gameManager.RestartGame();
        }
    }