【发布时间】:2016-09-19 00:42:01
【问题描述】:
我有一个名为“student”的游戏对象,它附加了一个脚本,然后我手动复制它(ctrl+D),这样每个复制的学生对象都具有相同的脚本组件。这是脚本(因为太长,不完整)
public class StudentScript : MonoBehaviour {
private Animator animator;
float sec;
public int m;
public GameManage gm;
void Start () {
animator = GetComponent<Animator> ();
sec = 0f;
m = 0;
}
void Update () {
sec+=Time.deltaTime;
if (m == 5 && animator.GetInteger ("Behav") == 0) {
animator.SetTrigger ("Finish");
}
}
//this is called from another script
public void ResetStudentBehaviour(){
if (animator.GetInteger ("Behav") != 0) {
animator.SetInteger ("Behav", 0);
sec = 0f;
if (m < 5) {
m++;
}
}else
Debug.Log ("student done <3");
}
}
我想要 => 如果每个学生的 m 值 m == 5,那么游戏结束。到目前为止我所做的是 GameManage 脚本中的 StudentScript(公共,所以我必须手动设置所有实例),然后检查每个学生的 m 值
public StudentScript stu1, stu2;
void Update () {
if (stu1.m == 5 && stu2.m == 5) {
StartCoroutine (ChangeScene());
}
}
IEnumerator ChangeScene(){
yield return new WaitForSeconds (10);
SceneManager.LoadScene(5);
}
有没有一种简单的方法可以在不使用if (stu1.m == 5 && stu2.m == 5) 的情况下检查所有学生对象的 m 值,因为在每个级别中,学生的数量都是不同的,所以我想为所有级别制作一个动态脚本
【问题讨论】:
标签: c# unity3d unityscript gameobject