unity脚本测试循环(if/while)能否使用【c#】
update为每帧跑一次,本身是一个循环。
写了这个脚本,判断在update中if/while循环能否正常使用。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 验证update里 可不可以while或者if
// 发现都ok
public class Cycle_Try : MonoBehaviour
{
int i = 0; // 循环变量
int[] ListTmp = { 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
// Start is called before the first frame update
void Start()
{
Debug.LogFormat("Start开始运行。");
}
// Update is called once per frame
void Update()
{
//Debug.LogFormat("Update开始运行。");
// RunProcess(); // 这个用的while
RunProcessIf(); // 这个用的if
}
public void RunProcess()
{
while (i <= 9)
{
Debug.LogFormat("循环变量为{0},", i);
i = i + 1;
}
}
public void RunProcessIf()
{