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;
    }
}
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,903
Location
Sydney, Australia
Programming Experience
10+
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?
 

lekomajko

New member
Joined
Jul 15, 2021
Messages
2
Programming Experience
Beginner
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
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
3,364
Location
Chesapeake, VA
Programming Experience
10+
Moving thread out of C# General Discussion. This looks to be Unity specific...
 
Top Bottom