- Home /
Problem occurs in Jumping
In my game I want my player jump without fire but when i press the button its jump also and fire too in same moment. In this Update method :- I used input.getbutton where my player fire continuously still hold the button. but in JumpButton method its Jump also and fire too.
// Use this for initialization
void Start () {
isJumped = true;
}
// Update is called once per frame
void Update(){
if (!transform.GetChild (0).gameObject.GetComponent<PlayerHealth> ().hasDied) {
if (Input.GetButton ("Fire1") && Time.time > firespeed && isJumped == true) {
nextFire = myTime + firespeed;
newProjectile = Instantiate (projectile, transform.position, transform.rotation) as GameObject;
nextFire = nextFire - myTime;
myTime = 0.0F;
// EnergyCharging ();
}
}
}
void JumpButton(){
if(!transform.GetChild(0).gameObject.GetComponent<PlayerHealth>().hasDied){
if (grounded) {
grounded = true;
myRigidBody.AddForce (new Vector2 (0, jumpPower), ForceMode2D.Impulse);
if(myRigidBody.velocity.y > jumpPower){
myRigidBody.velocity = new Vector2 (0, jumpPower);
}
animator.SetBool ("isGrounded", grounded);
}
}
}
Comment