2017-12-03 58 views
0

我想在Unity中產生一組座標的預製,但是這種情況不斷出現。'Spawning.SpawnCube'是一個'字段',但'方法組'被期望

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

public class Spawning : MonoBehaviour { 

    public GameObject TestCube; 
    public GameObject SpawnCube; 
    public float CubeFallTime = 7.0f; 
    public Vector3 Pos; 

    void Start() 
    { 
     StartCoroutine(SpawnCube()); 
    } 

    IEnumerator Spawn() 
    { 
     yield return new WaitForSeconds(CubeFallTime); 
     Instantiate(TestCube, new Vector3(0, 6, 0), Quaternion.identity); 
    } 
} 

回答

0

SpawnCube是一個變量,而您試圖訪問它作爲一種方法就是爲什麼誤差保持未來

你應該做這樣的事情

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

public class Spawning : MonoBehaviour { 

    public GameObject TestCube; 
    public GameObject SpawnCube; 
    public float CubeFallTime = 7.0f; 
    public Vector3 Pos; 

    void Start() 
    { 
     StartCoroutine(Spawn()); 
    } 

    IEnumerator Spawn() 
    { 
     yield return new WaitForSeconds(CubeFallTime); 
     Instantiate(TestCube, new Vector3(0, 6, 0), Quaternion.identity); 
    } 
}` 

應該做工精細請搜索互聯網這種錯誤之前發佈它作爲一個問題在堆棧 謝謝

相關問題