void OnCollisionStay2D(Collision2D other) { // Debug.Log ("collStay"); bool hitACP = other.gameObject.tag == "checkPointPlat"; if (hitACP) { hitCP = true; } if (other.gameObject.tag == "targetPlatform" || hitACP) { // platformBehavoir platScript = other.gameObject.GetComponent<platformBehavoir> (); togglePlatformBehavior platScript = other.gameObject.GetComponent <togglePlatformBehavior> (); if (!platScript.inactive) { lastTouchedPost = false; if (Input.GetKeyDown("down") || Input.GetKeyDown("s") && !hitACP) { platScript.letPlayerFallThrough(); //fixme play fall through animation? } onPlatform = true; } } else if (other.gameObject.tag == "bottomEdge") { lastTouchedPost = false; onPlatform = true; } else if (other.gameObject.tag == "post") { post postScript = other.gameObject.GetComponent <post> (); if (!postScript.inactive) { if (Input.GetKeyDown("down") || Input.GetKeyDown("s")) { postScript.letPlayerFallThrough(); } onPlatform = true; } } }
// Update is called once per frame void Update() { if (debugging) { if (Input.GetKeyDown("]")) { //turn blue grabOrb(0, Color.blue); } else if (Input.GetKeyDown("[")) { grabOrb(1, Color.red); } } if (health > 0) { moveCameraHeight(); if (!startCam && !bossBeat) { //print(myRig.velocity.x); changeSprite(); myRig.velocity = new Vector2(myRig.velocity.x * hFirction, myRig.velocity.y); Collider2D[] colliders = Physics2D.OverlapCircleAll(m_GroundCheck.position, k_GroundedRadius, 1 << LayerMask.NameToLayer("Platforms")); if (colliders.Length < 1) { canJump = false; //colliding with nothing onPlatform = false; } bool canJumpOnOne = false; for (int i = 0; i < colliders.Length; i++) { try { togglePlatformBehavior platScript = colliders [i].GetComponent <togglePlatformBehavior> (); if (!platScript.inactive) { canJumpOnOne = true; break; } } catch (Exception e) { if (colliders [i].gameObject != gameObject) { canJumpOnOne = true; break; } } } if (canJumpOnOne) { canJump = true; } if (Input.GetKeyDown("up") || Input.GetKeyDown("w")) { if (canJump || canDoubleJump) { onPlatform = false; if (!bossBeat) { myAudio.clip = jumpSound; } // float yForce = jumpPower * 50f; myRig.velocity = new Vector2(myRig.velocity.x, getJumpPower()); if (canDoubleJump && !canJump) { canDoubleJump = false; if (!bossBeat) { myAudio.clip = doubleJumpSound; } // yForce *= 0.75f; } // myRig.AddForce (new Vector2 (0f, yForce)); if (!bossBeat) { myAudio.Play(); } canJump = false; } } else if ((Input.GetKey("up") || Input.GetKey("w")) && myRig.velocity.y < -5f && !canJump) { floatDown(); } else if ((Input.GetKeyUp("up") || Input.GetKeyUp("w") && floating)) { unfloatDown(); } if (Input.GetKey("left") || Input.GetKey("a")) { if (myRig.velocity.x > -maxRunSpeed) { myRig.velocity = new Vector2(myRig.velocity.x - runSpeed, myRig.velocity.y); } if (myRig.velocity.x <= -maxRunSpeed) { myRig.velocity = new Vector2(-maxRunSpeed, myRig.velocity.y); } } else if (Input.GetKey("right") || Input.GetKey("d")) { if (myRig.velocity.x < maxRunSpeed) { myRig.velocity = new Vector2(myRig.velocity.x + runSpeed, myRig.velocity.y); } if (myRig.velocity.x >= maxRunSpeed) { myRig.velocity = new Vector2(maxRunSpeed, myRig.velocity.y); } } } } else { if (!marioDeathJump) { marioDeathJump = true; myCollider.enabled = false; myRig.velocity = new Vector2(0f, 45f); mySprite.sprite = jumpSprite; mySprite.flipY = true; Invoke("respawn", 2f); } } }