chargedshot problem

Updated on October 6, 2017 in General
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
3 on October 5, 2017

Hello, I’m practicing in unity doing a megaman-like attack. I can do the intermediate charged shot, but my character can’t do the full charged shot. This is my code:

if (Input.GetKey(chargeshoot) ) {
chargetimer += Time.deltaTime;
}
if (Input.GetKeyDown (chargeshoot)) {
Instantiate (Bala, firePoint.position, firePoint.rotation);
}
if (Input.GetKeyUp (KeyCode.A) && isOnground) {
anim.SetTrigger ("shoot");
}
if(Input.GetKeyUp (chargeshoot) && (chargetimer > 0.3f) && isOnground) {
Instantiate (Bala2, firePoint.position, firePoint.rotation);
chargetimer = 0;
}
//bala3
if (Input.GetKeyUp (chargeshoot)&& (chargetimer >1 )) {
Instantiate (Bala3, firePoint.position, firePoint.rotation);
}

 

  • Liked by
Reply
2 on October 5, 2017

I have to understand, is it intentionally that all “if” statements can be true and Bala to Bala3, so 3 gameObjects, will be spawned at your firePoint?

If not perhaps it is just a squence error, so check the one with the longest chargetimer first:

//bala3
if (Input.GetKeyUp (chargeshoot)&& (chargetimer >1 ))
{
Instantiate (Bala3, firePoint.position, firePoint.rotation);
chargetimer = 0;
}  
else if(Input.GetKeyUp (chargeshoot) && (chargetimer > 0.3f) && isOnground)
{
Instantiate (Bala2, firePoint.position, firePoint.rotation);
chargetimer = 0;
}

 

on October 6, 2017

Yeah, it was a squence error, thanks. I already solved the problem

Helpful
on October 6, 2017

Very well.

Show more replies
  • Liked by
Reply
Cancel