So i’ve been stuck at this for an hour now which is strange because I didnt think it would be this hard.
So im having my ball script spawn an arrow before the player launched the ball the goal is that the player will be able to choose where the ball is shot depending on the rotation of the arrow but i can’t seem to destroy the arrow after creating it without issues.
Code
public void Launch_Ball()
{
if (Input.GetMouseButtonDown(1))
{
Vector3 spawnPoint = new Vector3(this.transform.position.x, -10.5f, 10f);
lauchingBall = true;
Instantiate(arrow, spawnPoint , arrow.transform.rotation);
}
else if (Input.GetMouseButtonUp(1))
{
lauchingBall = false;
LaunchedBall = true;
Destroy(arrow.gameObject); // Written like this the newly made arrow wont be destroyed.
GetComponent<Rigidbody>().velocity = new Vector3(BallVelocityX, 0f, BallVelocityZ);
}
}
If I assign the arrow gamebject to the newly instantiated arrow, it will destroy it but then i cant spawn it again.
ex: arrow = Instantiate(arrow, spawnPoint , arrow.transform.rotation);