gpt4 book ai didi

c# - 脚本需要Derive from MonoBehaviour,不能带参数

转载 作者:太空宇宙 更新时间:2023-11-03 22:30:49 26 4
gpt4 key购买 nike

我在 Unity 中有项目,也是 C# 的新手。问题是我收到错误脚本需要从 MonoBehaviour 派生。我明白这是什么意思,但是当我使用 MonoBehaviour 时,我遇到了很多这样的错误:

Errors in console

如果有人能解释我做错了什么,我会很高兴 - 谢谢 stackoverflow 的好人!

每个脚本都连接到BaseWindow

命名空间 BlGame.View{ 公共(public)抽象类 BaseWindow { protected 变换 mRoot;

    protected EScenesType mScenesType; 
protected string mResName;
protected bool mResident;
protected bool mVisible = false;



public abstract void Init();


public abstract void Realse();


protected abstract void InitWidget();


protected abstract void RealseWidget();


protected abstract void OnAddListener();


protected abstract void OnRemoveListener();


public abstract void OnEnable();


public abstract void OnDisable();


public virtual void Update(float deltaTime) { }


public EScenesType GetScenseType()
{
return mScenesType;
}


public bool IsVisible() { return mVisible; }


public bool IsResident() { return mResident; }


public void Show()
{
if (mRoot == null)
{
if (Create())
{
InitWidget();
}
}

if (mRoot && mRoot.gameObject.activeSelf == false)
{
mRoot.gameObject.SetActive(true);

mVisible = true;

OnEnable();

OnAddListener();
}
}


public void Hide()
{
if (mRoot && mRoot.gameObject.activeSelf == true)
{
OnRemoveListener();
OnDisable();

if (mResident)
{
mRoot.gameObject.SetActive(false);
}
else
{
RealseWidget();
Destroy();
}
}

mVisible = false;
}

//预加载
public void PreLoad()
{
if (mRoot == null)
{
if (Create())
{
InitWidget();
}
}
}

//延时删除
public void DelayDestory()
{
if (mRoot)
{
RealseWidget();
Destroy();
}
}


private bool Create()
{
if (mRoot)
{
Debug.LogError("Window Create Error Exist!");
return false;
}

if (mResName == null || mResName == "")
{
Debug.LogError("Window Create Error ResName is empty!");
return false;
}

if (GameMethod.GetUiCamera.transform== null)
{
Debug.LogError("Window Create Error GetUiCamera is empty! WindowName = " + mResName);
return false;
}

GameObject obj = LoadUiResource.LoadRes(GameMethod.GetUiCamera.transform, mResName);

if (obj == null)
{
Debug.LogError("Window Create Error LoadRes WindowName = " + mResName);
return false;
}

mRoot = obj.transform;

mRoot.gameObject.SetActive(false);

return true;
}

//销毁窗体
protected void Destroy()
{
if (mRoot)
{
LoadUiResource.DestroyLoad(mRoot.gameObject);
mRoot = null;
}
}


public Transform GetRoot()
{
return mRoot;
}

}

像这样的东西:

 public class UIGuideWindow : BaseWindow
{

public UIGuideWindow()
{
//mScenesType = EScenesType.EST_Login;
//mResName = GameConstDefine.UIGuideRestPath;
//mResident = false;
}

最佳答案

Unity 更新函数不能有任何这样的参数:Update(float deltaTime),这是 unity 而不是虚幻引擎:))

要解决此问题,请删除 float deltaTime ,并改用 Time.deltaTime在函数实现本身内部

关于c# - 脚本需要Derive from MonoBehaviour,不能带参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57943720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com