简体   繁体   中英

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. Any clue as to what I'm doing wrong here?

A small typo. Your start method needs to have a capital s.

 private void Start()
 {
     LoadCard(card);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM