- Home /
overloaded Raycast
So ive been looking around, and I cant find a clear answer for this. I thought by asking this I might be helping others too.
So I'm trying to raycast from a point downwards, and check if it hits a certain collider. I wanted to limit it to raycast to about 2000, but I keep on getting the overloaded error:
Assets/treeTool/treeTool.cs(77,52): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, float, int, UnityEngine.QueryTriggerInteraction)' has some invalid arguments
from the code :
RaycastHit treeHit;
Ray treeRay = new Ray (currentTreeRayPos, Vector3.down);
if(Physics.Raycast(treeRay, 1000, out treeHit, landOnly)){
if (treeHit.collider.GameObject.tag == "land") {
Instantiate (tree [0], treeHit.point, Quaternion.identity);
}
}
It seems there isn't enough space in a raycast to specify the start point, direction, max distance, out hit, and a layermask....... I'm rattling my brain (and google) trying to find a straight answer, any help u can give is appreciated. Thanks ^-^
RaycastHit treeHit; Ray treeRay = new Ray(currentTreeRayPos, Vector3.down);
if(Physics.Raycast(treeRay, out hit, 1000, landOnly)) {
if(treeHit.transform.tag == "land") { Instantiate(tree[0], treeHit.point, Quaternion.identity); }
}
Does this work? Note I put the range to be 1000, so if you wanted it to be 2000 you can change it.