@SevrichKing

Как с помощью тэга назначить public Text -----; в unity C#?

66915670d08d6615514383.png

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Money : MonoBehaviour
{
    public int money;
    public int Up;
    public Text moneytext;
    public GameObject paceje;
    public GameObject player;

    void Start()
    {
        money = PlayerPrefs.GetInt("money", 0);
        moneytext = Text.FindWithTag("moneyText");
        player = GameObject.FindWithTag("Player");
    }

    void Update()
    {
        PlayerPrefs.SetInt("money", money);
        moneytext.text = "$" + money;
    }


    private void OnTriggerEnter(Collider player)
    {
        money = money + Up;
        Debug.Log("money+ " + Up);
       
    }
}


надо чтобы moneytext назначался объект с тэгом moneytext
  • Вопрос задан
  • 63 просмотра
Решения вопроса 1
@DrRen7
Text это компонент а через FindWithTag можно получить GO.
moneytext = GameObject.FindWithTag("moneyText").GetComponent<Text>();
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы