[英]Unity text not updating
I'm trying to get the title/description of a playing card to change by creating a card class that holds the information: 我正在尝试通过创建一个包含以下信息的纸牌类来获取要更改的纸牌的标题/说明:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu (menuName = "Card")]
public class Card : ScriptableObject
{
public string cardName;
public Sprite art;
public string cardDetail;
}
Then load it with another script: 然后用另一个脚本加载它:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CardViz : MonoBehaviour
{
public Text title;
public Text detail;
public Image art;
public Card card;
private void start()
{
LoadCard(card);
}
public void LoadCard(Card c)
{
if (c == null)
{
return;
}
card = c;
title.text = c.cardName;
detail.text = c.cardDetail;
art.sprite = c.art;
}
}
I created prefab with the basic layout of a card. 我用卡的基本布局创建了预制件。 Then I created a new asset value in unity for a card and given it a name and detail. 然后,我为卡统一创建了一个新资产值,并为其指定了名称和详细信息。 Then assigned it to the public valuable Card under CardViz along with the corresponding title, detail and image variable to create a new prefab but none of the text change when I drag the newly made prefab into the hierarchy. 然后将其与相应的标题,详细信息和图像变量一起分配给CardViz下的公用卡,以创建新的预制件,但是当我将新制作的预制件拖动到层次结构中时,文本均不变。 Any clue as to what I'm doing wrong here? 关于我在这里做错什么的任何线索吗?
A small typo. 一个小错字。 Your start method needs to have a capital s. 您的启动方法需要有一个大写字母s。
private void Start()
{
LoadCard(card);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.