![](/img/trans.png)
[英]How can I call the cancellation of a running method from another method. c# .core 2.2
[英]How can I call this function from another method in C#?
我正在尝试调用levelSystemAnimated.ExpSkip()
它需要使用另一种方法,因为我想将它与按钮一起使用。
[SerializeField]
private LevelUI levelUI;
private LevelSystem levelSystem = new LevelSystem();
void Start() {
LevelSystemAnimated levelSystemAnimated = new LevelSystemAnimated(levelSystem);
if (File.Exists(Application.persistentDataPath + "/data.save")) {
SaveData data = SaveSystem.LoadData();
levelSystemAnimated.AddLoadExp(data.exp);
levelSystemAnimated.SetLoadLevel(data.level);
levelSystem.SetLoadLevel(data.level);
levelSystem.AddLoadExp(data.exp);
}
levelSystem.AddExperience(0);
levelUI.SetLevelSystemAnimated(levelSystemAnimated);
levelUI.SetLevelSystem(levelSystem);
youCrashed.SetActive(false);
LoadPlusScore();
YouCrashed();
InvokeRepeating("AddPlusXP", 1.0f, 0.0f);
}
public void SkipExp() {
levelSystemAnimated.ExpSkip();
SkipExpButton.SetActive(false);
}
这是我的代码,没有实现。
请注意,我是初学者。
我会给你一个包含按钮的空游戏对象脚本的例子。
首先你需要访问脚本,你可以用
public levelSystemAnimated levelSystem;
并将脚本的游戏对象拖到检查器中,或者你可以
void Start()
{
GameObject levelSystem = GameObject.FindGameObjectWithTag("levelSystemObj");
//then you can easily access to the script with a GetComponent
}
无论哪种方式,您现在都可以访问脚本,因此您可以简单地
public void ButtonToPress()
{
levelSystem.SkipExp();
}
所以在按下按钮时,你输入 function ButtonToPress()
,当你按下它时,它会启动 function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.