小编Bra*_*-NB的帖子

TextMeshPro 空引用异常

编辑:解决了。使用TextMeshProUGUI代替TextMeshPro

背景:
我使用 TextMeshPro 来显示文本。我想通过脚本更改文本。问题是当我尝试更改它时会收到 NullReferenceException。

细节:

我的脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class UI_speed : MonoBehaviour {

    TextMeshPro textmeshPro;

    void Start () {
        textmeshPro = GetComponent<TextMeshPro>();
        textmeshPro.text = "test";
    }
}
Run Code Online (Sandbox Code Playgroud)

代码与TextMeshPro API匹配,所以我不确定发生了什么。我正在使用 Unity 5.6.1f1。任何帮助是极大的赞赏。谢谢你。 我的工作站

c# text unity5

6
推荐指数
2
解决办法
2434
查看次数

C++我是否错误地使用了void函数?

错误:

  • C2182:'tellStats':非法使用'void'类型
  • C2440:'初始化':无法从'std :: string'转换为'int'
  • 不允许不完整的类型.

所有这些错误都可以在这一行找到:

    //ClassPractice.cpp
    void tellStats(pick);
Run Code Online (Sandbox Code Playgroud)

哪个叫......

    //Functions.h
    void tellStats(string);
Run Code Online (Sandbox Code Playgroud)

这被定义为......

    //Functions.cpp
        void tellStats(string choice)
    {
        if (choice == "wizard")
            {
            cout << "These are the Wizard's stats:" << endl;
            cout << "Max HP: 80\nSpeed: 7\nAttack: 10" << endl;
            }
    }
Run Code Online (Sandbox Code Playgroud)

我不明白为什么我会收到这些错误.我不知道为什么int甚至涉及错误.在这些代码部分中,我没有看到任何涉及int的内容.我以为我正确使用'void'因为我不想用函数返回值.

c++ function void

2
推荐指数
1
解决办法
116
查看次数

C++我可以使用string :: at分配一个int吗?

在我的代码中我有这个:

int enemyNumber = numberType.at(0);
Run Code Online (Sandbox Code Playgroud)

numberType 是一个字符串.

第一个字符string numberType是'1'.但int enemyNumber在该任务之后变为48.

发生了什么,怎么让敌人的数字变成'1'?

c++ string int variable-assignment

1
推荐指数
2
解决办法
129
查看次数

标签 统计

c++ ×2

c# ×1

function ×1

int ×1

string ×1

text ×1

unity5 ×1

variable-assignment ×1

void ×1