Question by
cheeni75 · Jun 21, 2016 at 06:44 AM ·
mouseraycasthithit
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;
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612083344im_/https://answers.unity.com/themes/thub/images/avi.jpg)