Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- public class UISetupExample : MonoBehaviour
- {
- public StoryStep[] Steps;
- public GameObject prefab;
- private GameObject parent;
- private GameObject newobj;
- private string _headerText;
- private string _mainText;
- private Sprite _image;
- void Start()
- {
- parent = gameObject;
- foreach (var field in Steps)
- {
- newobj = Instantiate(prefab);
- newobj.transform.SetParent(parent.transform, true);
- if (field.Name.Any())
- {
- _headerText = newobj.transform.Find("HeaderText").gameObject.GetComponent<Text>().text;
- _headerText = field.Name;
- }
- else Debug.Log("Can't assign name");
- if (field.Description.Any())
- {
- _mainText = newobj.transform.Find("MainText").gameObject.GetComponent<Text>().text;
- _mainText = field.Description;
- }
- else Debug.Log("Can't assign description");
- if (field.Image != null)
- {
- _image = newobj.transform.Find("Image").gameObject.GetComponent<Image>().sprite;
- _image = field.Image;
- }
- else Debug.Log("");
- }
- }
- }
- [System.Serializable]
- public class StoryStep
- {
- public string Name;
- public string Description;
- public Sprite Image;
- }
Advertisement
Add Comment
Please, Sign In to add comment