Hello everyone,
I have one object shooting in x-y plane…,x means horizontal and y means vertical direction… My bullet is capsule game object with rigidbody component.
Now Whenever i touch on the screen , i want my bullet to translate towards that position.
For touch i have written code as below:
for (var i = 0; i < Input.touchCount; ++i) {
ray = Camera.mainCamera.ScreenPointToRay(Input.GetTouch(i).position);
switch(Input.GetTouch(0).phase)
{
case TouchPhase.Stationary:
if (Physics.Raycast(ray,hit))
{
bulletObject = Instantiate(bulletPrefab , bulletShootPoint.transform.position , bulletPrefab.transform.rotation);
// hitPoint = hit.point;
// var pos = Input.GetTouch(i).position;
hitPoint = Camera.main.ScreenToWorldPoint(Input.GetTouch(i).position);
}
case TouchPhase.Began:
break;
case TouchPhase.Moved:
break;
case TouchPhase.Ended:
break;
}
}
Which code should i write to shoot bullet at exact touch position? Please help me to solve this action. Please guide me.
Thanks in advance for helping me and supporting me…