Question by
Odinmiranda · Jan 19, 2018 at 11:35 PM ·
getcomponenterror build
problems with GetComponent,Problems with GetComponent
Hello Recently I started messing with Unity and I've been learning through tutorials. I started a project of a simple game of the type of survival and I was taking inventory and I came across a mistake, which I can not solve. Assets/Scripts/Inventario/ItemData.cs(18,69): error CS1061: Type UnityEngine.GameObject[]' does not contain a definition for
GetComponent' and no extension method GetComponent' of type
UnityEngine.GameObject[]' could be found. Are you missing an assembly reference?
the problem is GetComponent. Someone can help me?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ItemData : MonoBehaviour, IBeginDragHandler, IDragHandler,IEndDragHandler {
Inventory inv;
public Item item;
public int amount;
public int curSlot;
// Use this for initialization
void Start () {
inv = GameObject.FindGameObjectsWithTag("InventoryManager").GetComponent<Inventory>();
this.transform.position = inv.slots[curSlot].transform.position;
}
public void OnBeginDrag(PointerEventData eventData)
{
if(item.ID != 1)
{
this.transform.SetParent(this.transform.parent.parent.parent);
this.transform.position = eventData.position;
}
}
public void OnDrag(PointerEventData eventData)
{
if (item.ID != 1)
{
this.transform.position = eventData.position;
}
}
public void OnEndDrag(PointerEventData eventData)
{
this.transform.SetParent(inv.slots[curSlot].transform);
this.transform.position = inv.slots[curSlot].transform.position;
}
}
Comment
Your answer
