Здравствуйте, уважаемые форумчане. В unity я новичок. Подскажите пожалуйста, как решить ошибку с ScreenPointToRay(подчеркнута красным!)? Вот что выдает: "Inventory.cs(30,35): error CS1061: Type `object' does not contain a definition for `ScreenPointToRay' and no extension method `ScreenPointToRay' of type `object' could be found. Are you missing an assembly reference?" Код прилагается.За ранее благодарю.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Inventory : MonoBehaviour {
List<Item> item;
public GameObject cellContainer;
public KeyCode showInventory;
public KeyCode takeButton;
// Use this for initialization
void Start () {
item = new List<Item>();
cellContainer.SetActive(false);
for (int i = 0; i < cellContainer.transform.childCount; i++)
{
item.Add(new Item());
}
}
// Update is called once per frame
void Update ()
{
ToggleInventory();
if (Input.GetKeyDown(takeButton))
{
Ray ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 2f))
{
if (hit.collider.GetComponent<Item>())
{
for (int i = 0; i < item.Count; i++ )
{
if (item[i].id==0)
{
item[i] = hit.collider.GetComponent<Item>();
DisplayItems();
Destroy(hit.collider.GetComponent<Item>().gameObject);
break;
}
}
}
}
}
}
void ToggleInventory()
{
if (Input.GetKeyDown(showInventory))
{
if (cellContainer.activeSelf)
{
cellContainer.SetActive(false);
}
else
{
cellContainer.SetActive(true);
}
}
}
void DisplayItems()
{
for(int i = 0; i < item.Count; i++)
{
Transform cell = cellContainer.transform.GetChild(i);
Transform icon = cell.GetChild(0);
Image img = icon.GetComponent<Image>();
if (item[i].id != 0)
{
img.enabled = true;
img.sprite = Resources.Load<Sprite>(item[i].pathIcon);
}
else
{
img.enabled = false;
img.sprite = null;
}
}
}
}