Newer
Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class DisplayScrolls : MonoBehaviour
{
public Inventory inventory;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
public GameObject prefab;
public int x_Start;
public int y_Start;
public int X_Pacece_Between_Items;
public int y_Pacece_Between_Items;
public int number_of_Column;
// Start is called before the first frame update
void Start()
{
//CreateDisplay();
}
// Update is called once per frame
void Update()
{
UpdateDisplay();
}
public void UpdateDisplay()
{
for( int i = 0; i< inventory.Scrolls.Count; i++){
if(! inventory.Scrolls[i].isDisplayed){
var obj = Instantiate(prefab, Vector3.zero, Quaternion.identity, transform);
obj.GetComponent<RectTransform>().localPosition = GetPosition(i);
obj.GetComponentInChildren<Text>().text = inventory.Scrolls[i].item.Description;
inventory.Scrolls[i].isDisplayed = true;
}
}
}
public Vector3 GetPosition(int i)
{
return new Vector3(x_Start+ (X_Pacece_Between_Items * (i % number_of_Column)), y_Start + (-y_Pacece_Between_Items * (i / number_of_Column)), 0f);
}
}