void OnCollisionEnter2D(Collision2D other) { //fixme maybe need a destroying animation or particle effects if (!floorFire) { if (other.gameObject.tag == "player") { Debug.Log("hitting player"); other.gameObject.GetComponent <playerControler> ().getHit(damage); Debug.Log("get destroyed"); thud.Play(); getDestroyed(); lastTouchedPost = false; } else if (other.gameObject.tag == "bottomEdge") { // Debug.Log ("hit the bottom get destroyed"); lastTouchedPost = false; thud.Play(); getDestroyed(); } else if (other.gameObject.tag == "targetPlatform") { Debug.Log("hitting platform"); thud.Play(); // float yForce = 15f; // if (myRig.velocity.y > 0f) { // yForce = 0f; // } // Vector2 forceVector = new Vector2 (Random.Range (-20f, 20f), yForce); // myRig.AddForce (forceVector, ForceMode2D.Impulse); // addXYForce (15f, yForce); lastTouchedPost = false; } else if (other.gameObject.tag == "post") { thud.Play(); Debug.Log("hitting post"); post postScript = other.gameObject.GetComponent <post> (); // float magnitude = origPostMagnitude; if (postScript.togglePost && !postScript.inactive) { if (!lastTouchedPost) { postScript.active = false; lastTouchedPost = true; Debug.Log(myRig.velocity.y); addXYForce(0f, -600f * myRig.velocity.y); Destroy(gameObject, 2f); postScript.playSound(); } } } else if (other.gameObject.tag == "fireball") { lastTouchedPost = false; // getDestroyed (); } } }
private void postJump(post postScript) { float magnitude = origPostMagnitude; if (postScript.active && !postScript.inactive) { if (!lastTouchedPost) { magnitude = origPostMagnitude; } else { magnitude = -1f; } if (postScript.vertical) { myRig.velocity = new Vector2(myRig.velocity.x, myRig.velocity.y * magnitude); } else { myRig.velocity = new Vector2(myRig.velocity.x * magnitude, myRig.velocity.y); } postScript.active = false; lastTouchedPost = true; postScript.playSound(); //fixme set a max velo? } }