ItemContainer.cs now filling with files (not working)

This commit is contained in:
s-prechtl 2022-06-03 14:18:26 +02:00
parent 7ccf683005
commit 865fa08102
2 changed files with 22 additions and 11 deletions

View file

@ -31,20 +31,20 @@ public class HouseController : MonoBehaviour {
public void ToggleMenu() {
menu.gameObject.SetActive(!menu.gameObject.activeSelf);
float newPosY;
if (Camera.main != null) {
Vector3 pos = Camera.main.WorldToScreenPoint(transform.position);
float newPosX = pos.x;
float newPosY;
if (pos.y - 50 - ((RectTransform)menuPanel.transform).rect.height >= 0) { //check if bottom of panel is in screen
newPosY = pos.y - ((RectTransform)menuPanel.transform).rect.height;
} else {
newPosY = pos.y + ((RectTransform)menuPanel.transform).rect.height;
}
menuPanel.transform.position = new Vector3(pos.x, newPosY);
menuPanel.transform.position = new Vector3(newPosX, newPosY);
}
}
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class ItemContainer : MonoBehaviour {
@ -18,12 +19,22 @@ public class ItemContainer : MonoBehaviour {
#endregion
public Item[] allItems;
// Start is called before the first frame update
private List<Item> _allItems;
private void Start() {
string[] files =
Directory.GetFiles("Assets/Items", "*.cs", SearchOption.AllDirectories);
foreach (string file in files) {
_allItems.Add(Resources.Load<Item>("Assets/Items/" + file));
}
Debug.Log(files);
Debug.Log(_allItems);
}
public Item GetItemByName(String name) {
for (int i = 0; i < allItems.Length; i++) {
if (allItems[i].displayName == name) {
return allItems[i];
for (int i = 0; i < _allItems.Count; i++) {
if (_allItems[i].displayName == name) {
return _allItems[i];
}
}