- Home /
Question by
blackcode101 · Oct 11, 2020 at 01:12 PM ·
unity 2dshootinganimationspositions
health bar and shooting position are static and does not move with animation
Hi, i am making a small 2d game, i am still learning and new to unity. Currently i am facing this problem with shoot position and health bar position. when the player starts animating the health bar on the top of the player stays static and does not move during the animation, when the animation stops it does move when i simply move the player with idle animation. Same problem with shoot position, it always shoot from the same same position while in the animation the player position changes constantly. both objects are the child of the player.
the code i am using for shooting is:
private IEnumerator StartShooting()
{
yield return new WaitForSecondsRealtime(0.5f);
_shootCounter = 0;
while (_shootCounter < 3)
{
_firstCall = false;
_shootingCalled = true;
**_anim.SetBool("startshooting", true);**
**StartCoroutine(BurstFire());**
_isShootingOn = true;
yield return new WaitForSeconds(_anim.GetCurrentAnimatorStateInfo(0).length);
//_anim.SetBool("startshooting", false);
_isShootingOn = false;
//_shootCounter += 1;
//_shootingFinished = false;
//yield return new WaitForSeconds(1f);
}
_shootingFinished = true;
_stopTheDrop = false;
StartCoroutine(MoveLeft());
}
***public IEnumerator BurstFire()***
{
AudioSource.PlayClipAtPoint(_machinegunSound, Camera.main.transform.position);
for (int i = 0; i < 20; i++)
{
if (Time.timeScale < 0.9f)
{
yield return new WaitForSecondsRealtime(0.440f);
}
else
{
yield return new WaitForSecondsRealtime(0.1f);
}
***Instantiate(_heaveFire, _shootingPosition.position,_shootingPosition.rotation);***
}
}
Comment