Debug.Log()不显示任何内容

时间:2018-10-18 01:56:47

标签: c# unity3d

摘要


试图为机械师建立基础,只是试图让它在x量的时间过去后才真正触发。此刻,我正在使用Debug.Log()使y事件触发而显而易见。这不会打印任何内容到控制台,这是一个问题。基本上,我正在尝试设置一个残障机制,以便在时间流逝时,如果角色不采取任何措施避免对角色造成负面影响。

研究


Print/Debug.Log is not showing output on Unity Console

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);
    }


}

1 个答案:

答案 0 :(得分:2)

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

在我看来,您尝试调用的此函数是Coroutine。引用Unity的文档,可以在这里找到:Unity's Coroutine Documentation

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