- Home /
Question by
HammockHead · Jul 03, 2013 at 09:45 PM ·
raycastarraystagwaypointraycastall
How can I Raycast to multiple objects
I am trying to create a waypoint system, where at the start of the level each waypoint finds all the waypoints that it can "see." I want each waypoint to Raycast to all the other waypoints and store the waypoints that the Raycast can hit in an array. I get the error: No appropriate version of 'UnityEngine.Physics.RaycastAll' for the argument list '(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.RaycastHit)' was found.Here's the code:
var wayPoints : GameObject[];
var nextPoints : GameObject[];
var myPoint = transform.position;
function Start() {
wayPoints = GameObject.FindGameObjectsWithTag("Waypoint");
var hits : RaycastHit[];
var rayDirections : Vector3[] = (wayPoint.position - transform.position).normalized;
for (var i = 0; i < hits.length; i++) {
if (Physics.RaycastAll(myPoint, rayDirections[i], hits[i])) {
if ( hits.collider.gameObject.tag == "Waypoint" ) {
nextPoints = hits.collider.gameObject;
}
}
}
}
Comment
Best Answer
Answer by Graham-Dunnett · Jul 03, 2013 at 09:46 PM
`RaycastAll()` returns the hits
array, you don't pass it in as an argument.