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