I don’t understand RaycastAll, I know how to use Raycast, but I don’t understand how you loop through all the hit points, and then find the closest.
I need RaycastAll because I’m hitting myself, which is not supposed to happen.
Heres the code. Its just basically saying if I hit fire1 shoot a RaycastAll, but thats it… I don’t understand, and please explain how it works, so I can understand it.
Code:
using UnityEngine;
using System.Collections;
public class Shoot : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetButtonDown ("Fire1")){
Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
RaycastHit[] hits;
if(Physics.Raycast(ray, out hits)){
}
}
}
}