Hello everyone, I have something I hope I could get some help understanding.
So here how my set up works. I have A capsule which has a long cube as a child and on the cube is an empty game object at the very end of it. I'll refer to the capsule as the turret, the long cube as a barrel and empty as a Spawn Location. the barrel has the main camera attached to it as child as well. I managed to manually position a sprite on a 3d UI to represent where a projectile will land from the "Spawn Location";
However I want to do this with script and I have been really puzzled by this for a while now.
I've search and most people have suggested casting a ray and then using ray cast and worldtoscreenpoint.
Can I please get any suggestions on this please?
void Start ()
{
RaycastHit Hit
= new RaycastHit
(); Ray ray = CameraToUse.ScreenPointToRay (transform.position);
Debug.DrawRay (transform.position,Vector3.forward,Color.red);
if(Physics.Raycast (ray,out Hit))
{
Vector3 Pos = CameraToUse.WorldToScreenPoint (Hit.point);
Vector3 CrossPos
= new Vector3
(Pos
.x,Pos
.y,Cross
.position.z); Cross.localPosition = CrossPos; // Set the parent of the spirte to the location
print ("Pos " + Pos);
}
}