I tried to add accuracy to my raycast function in my gun script. Unfortunately i get these errors every time:
(53,16): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit, float, int)’ has some invalid arguments
(53,30): error CS1620: Argument #2' is missing out’ modifier
Can anyone help me with this?
Here is my script:
public int range = 10000;
public float spreadFactor = 0.02f;
public void fireShot(){
if (!am.IsPlaying (shoot))
{
Vector3 direction = transform.forward;
direction.x += Random.Range(-spreadFactor, spreadFactor);
direction.y += Random.Range(-spreadFactor, spreadFactor);
direction.z += Random.Range(-spreadFactor, spreadFactor);
am.CrossFadeQueued(shoot, 0.01f, QueueMode.PlayNow);
RaycastHit hit;
Ray ray = fpsCam.ScreenPointToRay (new Vector3 (Screen.width / 2, Screen.height / 2, 0));
if (Physics.Raycast (ray, direction, out hit, range))
{
if (hit.transform.tag == "Player")
{
hit.transform.GetComponent<PhotonView> ().RPC ("applyDamage", PhotonTargets.AllBuffered, damage);
}
GameObject particleClone;
particleClone = PhotonNetwork.Instantiate (hitPar.name, hit.point, Quaternion.LookRotation (hit.normal), 0) as GameObject;
Destroy (particleClone, 2);
Debug.Log (hit.transform.name);
}
}
jwulf
2
Looking at your call, you give the method
- A UnityEngine.Ray
- A Vector3
- A UnityEngine.RaycastHit (with out modifier)
- An int
which appearantly does not match with what arguments the method UnityEngine.Physics.Raycast (or any of its overloads) expects. Your should check Unity - Scripting API: Physics.Raycast for valid calls of the method. Roughly summarized, you can either use a UnityEngine.Ray OR two Vector3s (origin and direction) to describe the ray to be cast.