Question 'Transform' does not contain a definition for 'GameObject'

lekomajko

New member
Joined
Jul 15, 2021
Messages
2
Programming Experience
Beginner
Im getting the error message "error CS1061: 'Transform' does not contain a definition for 'GameObject' and no accessible extension method 'GameObject' accepting a first argument of type 'Transform' could be found"
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Grab : MonoBehaviour
{
    public Transform equipPosition;
    public float distance = 10f;
    GameObject currentWeapon;
     GameObject wp;

    bool grab;

    private void Update()
    {
        CheckWeapons();

        if (grab)
        {
            if(Input.GetKeyDown(KeyCode.E))
            {
                if(currentWeapon != null)
                    Drop();

                PickUp();
            }
        }
        if(currentWeapon !=null)
        {
            if (Input.GetKeyDown(KeyCode.Q))
                Drop();
        }
    }

    private void CheckWeapons()
    {
        RaycastHit hit;

       if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward,out hit, distance))
        {
            if(hit.transform.tag=="Grab")
            {
                Debug.Log("I can grab it!");
                grab = true;
                wp = hit.transform.GameObject;
            }
        }
        else
            grab = false;
    }

    private void PickUp()
    {
        currentWeapon = wp;
        currentWeapon.transform.position = equipPosition.position;
        currentWeapon.transform.parent = equipPosition;
        currentWeapon.transform.localEulerAngles = new Vector3(0f, 180f, 0f);
        currentWeapon.GetComponent<Rigidbody>().isKinematic = true;
    }
      private void Drop()
    {
        currentWeapon.transform.parent = null;
        currentWeapon.GetComponent<Rigidbody>().isKinematic = false;
        currentWeapon = null;
    }
}
 
I checked the documentation - just as you should have done - and it appears that the name is gameObject rather than GameObject. C# is case-sensitive and Unity seems to start all its property names with lower case. You're honouring that everywhere else so why not there?
 
I checked the documentation - just as you should have done - and it appears that the name is gameObject rather than GameObject. C# is case-sensitive and Unity seems to start all its property names with lower case. You're honouring that everywhere else so why not there?
Oh, I had no idea it would be a small g. Thank you i'm pretty new to coding. quite annoying that I have been sitting for several hours and google and it turned out to be a stupid miss ive made haha
 
Moving thread out of C# General Discussion. This looks to be Unity specific...
 
Back
Top Bottom