Unity报错 error CS0246: The type or namespace name ‘UI‘ could not be found

Unity报错 error CS0246: The type or namespace name ‘UI’ could not be found

在我导入老版本的UnityPackage到2021年1月份的Unity版本的时候,出现了许多警告和error,其中就包括了这样的一个错误:
The Type Or Namespace UI could not be found
具体的解决方案如下:
首先,在该错误的开头,加入引用
using UnityEngine.UI;
随后,将UI的前缀去掉;例如:
将*UI.Text变为Text*即可;
例如以下代码即可正确运行:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;//要更改的地方
 
 [RequireComponent(typeof(Text))] //要更改的地方
 public class ResourceDisplay : MonoBehaviour {
 
     enum resEnum {Wood, Iron, Stone, Gold, Food, Population }
     resEnum resSelect;
     private Text txtComp;  //要更改的地方
  
     void Start () {
         txtComp = GetComponent<Text>(); //要更改的地方
     }
     
     void Update () {
         switch (resSelect)
         {
             case resEnum.Wood:
                 txtComp.text = GVars.qWood.ToString();
                 break;
             case resEnum.Iron:
                 txtComp.text = GVars.qIron.ToString();
                 break;
             case resEnum.Stone:
                 txtComp.text = GVars.qStone.ToString();
                 break;
             case resEnum.Gold:
                 txtComp.text = GVars.qGold.ToString();
                 break;
             case resEnum.Food:
                 txtComp.text = GVars.qFood.ToString();
                 break;
             case resEnum.Population:
                 txtComp.text = GVars.qPop.ToString();
                 break;
         }
     }
 }
 
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值