I know this is a really silly question… But the ray is coming from the mouse poiner… And I would like it to come from the center of the screen (where the tip of the gun is)
Here is my script:
function Update()
{
if(Input.GetMouseButton(0)) // if the RIGHT button pressed
{
// casts a ray from the mouse pointer
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit: RaycastHit;
if(Physics.Raycast(ray, hit)) // if something hit, send the message
{
hit.collider.SendMessageUpwards("ApplyDamage", 20, SendMessageOptions.DontRequireReceiver);
}
}
}