- Home /
Question by
noviarhmynt · Mar 01, 2020 at 12:19 AM ·
uiscript.
Instantiate a cell of table in UI through script with data I got from scriptable object
I following a tutorial from Brackeys on youtube how to use scriptable objects.
So, basically I'm just making a scriptable object, then show it on the canvas of UI.
Here's the code:
public class EncyMush : ScriptableObject
{
public string titleName;
public Sprite image;
public string[] tableOfClasc;
public string[] tableOfName;
public string aliasName;
public string expl;
public string[] mycoChar;
public string furtherDetail;
public Sprite picFI1;
public Sprite picFI2;
}
then with the UI that I've been made, I assigned those value with this code:
public class MushroomDisplay : MonoBehaviour
{
public EncyMush mushroom;
public GameObject canvasParent;
public TMP_Text titleText;
public Image imageView;
public TMP_Text classification;
public TMP_Text binomialSynonim;
public TMP_Text alias;
public TMP_Text explanation;
public TMP_Text characteristics;
public TMP_Text furtherExpl;
public Image pict;
void Start()
{
for (int i = 0; i < 6; i++)
{
Instantiate(classification);
//classification.transform.SetParent(canvasParent.transform, false);
classification.text = mushroom.tableOfClasc[i];
}
}
}
on the code above, I could instantiate the classification (for example) but it appears not inside the canvas. how to fix this? I tried to parent them to the canvas but it's giving an error or not working.
Comment
Your answer
Follow this Question
Related Questions
How to draw dynamic new gui 0 Answers
Slider Not Working 0 Answers
How to convert a Mouse Input Combo System to Button? 1 Answer
How to resize an image by stretching only the center part 1 Answer
Unity Standard Assets 0 Answers