- Home /
arrow shooting
Hi. I've got some problems on managing arrow shooting, meaning i'm executing a draw animation ending in aiming position. staying there as long as i keep R-Key pressed. Releasing "R" the arrow is instantiate and shooted. So far so good, but I want to prevent the arrow to be shooted since the draw animation is finished, i don't want to use my bow as a 30 arrow per second machine gun...
public bool IsNocked { get; set; }
Start{ IsNocked = false; }
Update{ ShootArrow(); }
private void ShootArrow()
{
if (AmmoText.ammoAmount > 0)
{ //if have arrows left
if (Input.GetKeyDown(KeyCode.R))
{
StartCoroutine(LoadArrow());
}
if (IsNocked && Input.GetKeyUp(KeyCode.R))
{
nockArrowPrefab.gameObject.SetActive(false);
playerAnimations.Release_Range();
//Istanzio una nuova freccia nella posizione dell'arrowspawnpoint e la chiamo go
GameObject go = Instantiate(arrowPrefab, spellSpawn.position, Quaternion.identity);
Rigidbody rb = go.GetComponent<Rigidbody>();
rb.velocity = cam.transform.forward * shootForce;
AmmoText.ammoAmount -= 1;
crossair.SetActive(false);
IsAttacking = false;
IsNocked = false;
}
if (!IsNocked && Input.GetKeyUp(KeyCode.R))
{
nockArrowPrefab.gameObject.SetActive(false);
playerAnimations.Release_Range();//anim release
crossair.SetActive(false);
IsAttacking = false;
IsNocked = false;
return;
}
}
else
return;
}
public IEnumerator LoadArrow()
{
crossair.SetActive(true);
//showing fake arrow for the animation
nockArrowPrefab.gameObject.SetActive(true);
playerAnimations.Attack_Range(); //animation draw
IsNocked = true;
yield return new WaitForSeconds(0.5f);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612224238im_/https://answers.unity.com/themes/thub/images/avi.jpg)