In my game I want my player jump without firing their weapon, but when I press the button it jumps and also fires too in same moment.
In this Update method, I used Input.GetButton so my player will fire continuously while holding the button.
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);
}
}
}
isJumped
, inJumpButton()
method, set it to false; and inupdate()
methodif (Input.GetButton ("Fire1") && Time.time > speed && isJumped == true)
. Try this \$\endgroup\$