[SOLVED] Physics.Raycast invalid arguments

I’m trying to do a raycast on iPhone, but for some reason I keep getting errors about invalid arguments.

This is the code:

Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit = new RaycastHit();
if (Physics.Raycast (ray, hit))
{
    	Debug.DrawLine (ray.origin, hit.point);
}

These are the errors:

Assets/code/Game.cs(1388,21): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3)' has some invalid arguments

Assets/code/Game.cs(1388,21): error CS1503: Argument 1: Cannot convert type `UnityEngine.Ray' to `UnityEngine.Vector3'

I really don’t get it. This is what I find in the documentation of Unity iPhone:

static function Raycast (ray : Ray, out hitInfo : RaycastHit, distance : float = Mathf.Infinity, layerMask : int = kDefaultRaycastLayers) : bool

Anyone who sees what I’m doing wrong here? I restarted Unity, but that didn’t help.

I’m running Unity Version 1.5.1f2 (30369).

Note the “out” bit. Unlike Javascript, you have to actually write that.

–Eric

Wow. It works now. Very strange syntax. Weird that the compiler thinks the parameter list ‘Ray, RaycastHit’ looks more like ’ Vector3, Vector3’ than ‘Ray, out RaycastHit’.

Thanks for helping me out on this!

Thank you! :smile: