unity脚本测试循环(ifwhile)能否使用【c#】

本文通过一个Unity脚本实例,测试了在Update方法中使用C#的if和while循环是否正常工作。日志输出结果显示,这两个循环都能够完整执行。虽然测试表明循环运行无误,但若循环内包含其他指令,可能需要进一步验证其行为。
摘要由CSDN通过智能技术生成

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()
    {
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值