所以这是我的代码
public void CheckStatChal()
{
foreach (SpotUIBase menu in thisSpot.ownMenus)
{
if (menu.uiSort == SpotUISort.StatEvent)
{
if(menu != null)
Debug.Log("Menu name is "+menu.Name);
var statEvent = menu as StatEvent;
if (statEvent == null)
{
Debug.Log("Stat event is null, name is "+thisSpot.Name);
continue;
}
.......... [1]
public SpecialSpotClass thisSpot;
public abstract class SpecialSpotClass
{
public List<SpotUIBase> ownMenus = new List<SpotUIBase>();
....
public class SpotUIBase
{
public SpotUISort uiSort;
....
public class StatEvent : SpotUIBase
{
....
public enum SpotUISort{
Inn, Shop, Bar,
我现在正在使用Unity Engine。因此,如果运行此代码,我得到了debug.log("菜单名称为" 菜单。名称(;和debug.log(" stat事件为null,名称为" thespot.name(;两个都。为什么?菜单不是空的,但是在淡化之后,它变为null?我不明白为什么。
因此,在此代码中,我想在代码下执行[1]部分,但是[statevent]为null,因此,下面的所有代码均未通过(继续关键字(调用
为什么降落变为null?
请帮助。
,所以我搜索了谷歌搜索并确认了右下角方法,然后更改为语法。并解决。
这里已更改代码。
for (int i = 0; i < thisSpot.ownMenus.Count; i++)
{
if (thisSpot.ownMenus[i].uiSort == SpotUISort.StatEvent)
{
thisSpot.ownMenus[i] = SpotUI.Instance.StatEvent;
var ownMenu = (StatEvent) thisSpot.ownMenus[i];
Debug.Log("own menu is "+ownMenu.Name);
if ((!ownMenu.StatChal1.nowCoolTime && ownMenu.StatChal1 != null)
|| ownMenu.StatChal1 == null)
{
StatChallenge.Instance.MakeStatChal(this, ref ownMenu.StatChal1);
Debug.Log(ownMenu.StatChal1.Name);
ownMenu.SetChalInfo(ownMenu.StatChal1, 1);
chal1 = ownMenu.StatChal1;
}