- Home /
Shooting problem Unity3D C#
Hello. We have a problem in shooting ball. It is possible to shoot 3 times during the game. However, there are cases when the ball is taken out of the calculation but does not shoot.
if (!IsPointerOverUIObject() && Input.GetMouseButtonUp(0) && readyToshoot) // Shoot the ball
{
ball.GetComponent<Rigidbody>().AddForce(dir * ballForce, ForceMode.Impulse);
StartCoroutine(BallSpawn());
readyToshoot = false;;
}
IEnumerator BallSpawn()
{
BallsCounter.Ball--;
yield return new WaitForSeconds(1.5f);
other.RepositionalBall();
}
public void RepositionalBall()
{
this.gameObject.tag = "Ball";
this.gameObject.SetActive(false);
transform.position = SpawnPos;
rb.velocity = new Vector3 (0f, 0f, 0f);
this.GetComponent<Animator>().enabled = true;
gameObject.SetActive(true);
StartCoroutine(SetReadyToShoot());
}
IEnumerator SetReadyToShoot()
{
yield return new WaitForSecondsRealtime(1f);
GameManager.instance.readyToshoot = true;
}
commenting your own post with a rethoric question wont make people solve your problem faster... You could ins$$anonymous$$d be more specific about what "However, there are cases when the ball is taken out of the calculation but does not shoot." actually means as this seems to be the crucial part of your question.
Your answer
![](https://koobas.hobune.stream/wayback/20220613001006im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to to not move when shooting? 0 Answers
How : Player move forward automatically (global Z axis) & 'not' the direction it's facing 3 Answers
I Want To Shoot Bullets Correctly. 2 Answers
Shooting bullets in different patterns 0 Answers
Target Lookat not working . I want Z axis to rotate only. 2 Answers