2017-07-03 36 views
-1

[Unity Version 5.6.1f1; Visual Studio 2017]Unity Tutorial,IEnumerator ShotEffect(),error

嗨, 我正在閱讀使用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; 
     } 

回答

3

您已經定義ShotEffectUpdate功能。檢查你的大括號。

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