I want it so there is a ray cast in the middle of the camera. The raycast goes far but not infinite. When i shoot my gun, the bullet goes towards where the raycast hits an object. can any one help me with this? Thanks!
1 Answer
1 function Update()
{
if(Input.GetMouseButton(0))
{
var ray = camera.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit))
{
if(hit.transform == instruction)
{
inst = true;
}
if(hit.transform == start)
{
Debug.Log("start");
}
}
}
}
Are you sure you ned a raycast if you're going to instantiate a bullet? You could probably just send out the projectile forward.
– Jason_DB