Touching anywhere on screen the Bow is releasing the arrow

Touching anywhere on screen the Bow is releasing the arrow. I need help to convert it to touching only bow the arrow has to release not whole screen . i tried many ways but not working please help,Thank you.

public void prepareArrow() {
// get the touch point on the screen

	mouseRay1 = Camera.main.ScreenPointToRay(Input.mousePosition);
	if (Physics.Raycast(mouseRay1, out rayHit, 1000f) && arrowShot == false)

		
	{
		
		// determine the position on the screen
		posX = this.rayHit.point.x;
		posY = this.rayHit.point.y;
		// set the bows angle to the arrow
		Vector2 mousePos = new Vector2(transform.position.x-posX,transform.position.y-posY);
		float angleZ = Mathf.Atan2(mousePos.y,mousePos.x)*Mathf.Rad2Deg;
		transform.eulerAngles = new Vector3(0,0,angleZ);
		// determine the arrow pullout
		length = mousePos.magnitude / 3f;
		length = Mathf.Clamp(length,0,1);
		// set the bowstrings line renderer
		stringPullout = new Vector3(-(0.44f+length), -0.06f, 2f);
		// set the arrows position
		Vector3 arrowPosition = arrow.transform.localPosition;
		arrowPosition.x = (arrowStartX - length);
		arrow.transform.localPosition = arrowPosition;
	}
	arrowPrepared = true;
}

1 Answer

1

Hi,

You should check the rayHit parameter to do your stuff.

Like, using rayHit param you can access the hit object and check that it is Arrow or not and then you can do your work accordingly.