Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

FPS Modular System Errors

I am a noob at Unity, and I'm trying to make a bullet hell prototype game. I've managed to get rid of problems in the code, but with some I do not understand. As I'm trying to compile the code:

using System.Collections.Generic;

using System.Collections;

using UnityEngine;

public class WeaponManager : MonoBehaviour


  public float pickupRange;

  public float pickupRadius;

  public int weaponLayer;

  public Transform weaponHolder;

  public Transform playerCamera;

  private bool isWeaponHold;

  private Weapon holdWeapon;

  private void Update()


    if (isWeaponHold)


      if (Input.GetKeyDown(KeyCode.Q))



        holdWeapon = null;

        isWeaponHold = false;



    else if (Input.GetKeyDown(KeyCode.E)) {

      var hitList = new RaycastHit[256];

      var HitNumber = Physics.CapsuleCastNonAlloc(playerCamera.position, playerCamera.position + playerCamera.forward * pickupRange, pickupRadius, playerCamera.forward, hitList);

      var realList = new List<RaycastHit>();

      for (var i = 0; i < HitNumber; i++) {

        var hit = hitList[i];

        if (hit.transform.gameObject.layer != weaponLayer) continue;

        if (hit.point ==




        else if (Physics.Raycast(playerCamera.position, hit.point - playerCamera.position, out var hitInfo, hit.distance + 0.1f && hitInfo.transform == hit.transform))





      if (realList.Count == 0) return;

      realList.Sort((hit1, hit2) => {

        var dist1 = GetDistanceTo(hit1);

        var dist2 = GetDistanceTo(hit2);

        return Mathf.Abs(dist1 - dist2) < 0.001f ? 0 : dist1 < dist2 ? -1 : 1;


      isWeaponHold = true;

      holdWeapon = realList[0].transform.GetComponent<Weapon>;




  private float GetDistanceTo(RaycastHit hit)


    return Vector3.Distance(playerCamera.position, hit.point == ? hit.transform.position : hit.point);



I get these 2 errors:

Assets\Scripts\WeaponManager.cs(41,140): error CS8196: Reference to an implicitly-typed out variable 'hitInfo' is not permitted in the same argument list.


Assets\Scripts\WeaponManager.cs(56,48): error CS0428: Cannot convert method group 'GetComponent' to non-delegate type 'Weapon'. Did you intend to invoke the method?

I don't know how to fix them, and if someone here knows the answer to these problems, I'd be really grateful.


  • MrSlugMrSlug Member
    edited May 2020

    Hey @Freddson,

    Your first error is because the out keyword provides you with a reference to "hitInfo", the reason this is erroring is a missing closing bracket in your Physics.Raycast function.

    if (Physics.Raycast(playerCamera.position, hit.point - playerCamera.position, out var hitInfo, hit.distance + 0.1f ) && hitInfo.transform == hit.transform ) )

    Your second error is due to you missing closing brackets

    holdWeapon = realList[0].transform.GetComponent<Weapon>();

    When calling GetComponent, you write it was GetComponent<Type>().

    I've not been able to test your script, but let me know if this works!



  • Hey @MrSlug,

    thanks! I don't have access to the pc with the project right now, but tomorrow i'll add your modifications to the script. Thanks!

  • @MrSlug,

    your modifications worked! Thanks so much!

  • MrSlugMrSlug Member


    No worries, good luck!

Sign In or Register to comment.