【问题标题】:Unity Tutorial, IEnumerator ShotEffect(), errorUnity教程,IEnumerator ShotEffect(),错误
【发布时间】:2017-07-03 20:32:56
【问题描述】:

[Unity 版本 5.6.1f1; Visual Studio 2017]

嗨, 我正在学习使用 Raycast 的基本 Unity FPS 教程。调用时出现错误

私有 IEnumerator ShotEffect()

如下,

功能“本地函数”在 C#4 中不可用。请使用语言版本 7 或更高版本。

我该如何解决这个问题?这是从 Unity 教程中复制/粘贴的。这种类型的调用有替代方法吗? https://unity3d.com/learn/tutorials/lets-try/shooting-with-raycasts?playlist=41639&_ga=2.32575166.1847645017.1499027918-1229599585.1498623818

 void Update() {
        if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
        {
            // Update the time when our player can fire next
            nextFire = Time.time + fireRate;

            // Start our ShotEffect coroutine to turn our laser line on and off
            StartCoroutine(ShotEffect()); //**Call here**

            // Create a vector at the center of our camera's viewport
            Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

            // Declare a raycast hit to store information about what our raycast has hit
            RaycastHit hit;


        }

         private IEnumerator ShotEffect() //**Error here**
        {
            // Play the shooting sound effect
            gunAudio.Play();

            // Turn on our line renderer
            laserLine.enabled = true;

            //Wait for .07 seconds
            yield return shotDuration;

            // Deactivate our line renderer after waiting
            laserLine.enabled = false;
        }

【问题讨论】:

    标签: c# debugging unity3d ienumerator


    【解决方案1】:

    您已经在Update 函数内部 定义了ShotEffect。检查你的牙套。

        void Update() {
            if (Input.GetButtonDown("Fire1") && Time.time > nextFire)
            {
                // Update the time when our player can fire next
                nextFire = Time.time + fireRate;
    
                // Start our ShotEffect coroutine to turn our laser line on and off
                StartCoroutine(ShotEffect()); //**Call here**
    
                // Create a vector at the center of our camera's viewport
                Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
    
                // Declare a raycast hit to store information about what our raycast has hit
                RaycastHit hit;
    
            }
    
        } // Add brace here
    
        private IEnumerator ShotEffect()
        {
            // Play the shooting sound effect
            gunAudio.Play();
    
            // Turn on our line renderer
            laserLine.enabled = true;
    
            //Wait for .07 seconds
            yield return shotDuration;
    
            // Deactivate our line renderer after waiting
            laserLine.enabled = false;
        }
    

    【讨论】:

      猜你喜欢
      • 2020-01-01
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多