1

概括


试图为一个机制建立基础,只是试图让它在 x 时间过去后真正触发。目前,Debug.Log()如果 y 事件已触发,我正在使用它来说明这一点。这不会向控制台打印任何内容,这是一个问题。基本上,我正在尝试设置一个残废机制,所以当时间过去时,如果他们不采取措施避免它,就会对角色施加负面影响。

研究


Print/Debug.Log 未在 Unity 控制台上显示输出

https://docs.unity3d.com/ScriptReference/Debug.Log.html

问题


世界上正在发生什么?我已经确保我知道的所有问题都可能导致问题并非如此。不幸的是,这些问题似乎并非如此。那么有什么想法吗?代码如下。很抱歉复制了完整的内容,但我无法确定问题出在哪里。

代码


using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Cripple:MonoBehaviour
{
    public int EffectMagnitude;
    public string EffectType;
    public int TimeForIncrease;

    private void Start()
    {
        EffectStart();
    }

    private void Update()
    {

    }


    IEnumerator EffectStart()
    {
        int CounterCripple = 0;
        do
        {
            Debug.Log("Has run: " + CounterCripple);
            if (CounterCripple >= TimeForIncrease && CounterCripple < TimeForIncrease * 2)
            {
                if (EffectType == "Hunger")
                {
                    Debug.Log("<color=blue> Hunger effect triggered</color><color=green> Tier One</color>");
                }

                else if (EffectType == "Restless")
                {
                    Debug.Log("<color=blue> Restless effect triggered</color><color=green> Tier One</color>");
                }

                else if (EffectType == "Thirst")
                {
                    Debug.Log("<color=blue> Thirst effect triggered:</color><color=green> Tier One</color>");
                }
            }

            else if (CounterCripple >= TimeForIncrease * 2 && CounterCripple < TimeForIncrease * 3)
            {
                if (EffectType == "Hunger")
                {
                    Debug.Log("<color=blue> Hunger effect triggered</color><color=orange> Tier Two</color>");
                }

                else if (EffectType == "Restless")
                {
                    Debug.Log("<color=blue> Restless effect triggered</color><color=orange> Tier Two</color>");
                }

                else if (EffectType == "Thirst")
                {
                    Debug.Log("<color=blue> Thirst effect triggered:</color><color=orange> Tier Two</color>");
                }
            }

            else if (CounterCripple >= TimeForIncrease * 3)
            {
                if (EffectType == "Hunger")
                {
                    Debug.Log("<color=blue> Hunger effect triggered</color><color=red> Tier Three</color>");
                }

                else if (EffectType == "Restless")
                {
                    Debug.Log("<color=blue> Restless effect triggered</color><color=red> Tier Three</color>");
                }

                else if (EffectType == "Thirst")
                {
                    Debug.Log("<color=blue> Thirst effect triggered:</color><color=red> Tier Three</color>");
                }
            }
            CounterCripple++;
            yield return new WaitForSecondsRealtime(1);
        } while (true);
    }


}
4

1 回答 1

2

使用StartCoroutine(EffectStart())而不是仅EffectStart().

在我看来,你试图调用的这个函数是一个Coroutine. 引用 Unity 的文档,可在此处找到:Unity 的协程文档

"要设置协程运行,需要使用 StartCoroutine 函数"

于 2018-10-18T02:19:18.357 回答