2014-03-30 50 views
0
function Start() 
{ 
    var linkedTerrain:Terrain = gameObject.GetComponent(Terrain); 
    _terrainGrid[0,0] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[0,1] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[0,2] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[1,0] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[1,1] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[1,2] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[2,0] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[2,1] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 
    _terrainGrid[2,2] = Terrain.CreateTerrainGameObject(linkedTerrain.terrainData).GetComponent(Terrain); 

    _terrainGrid[0,0].transform.constantForce = Vector3(0,0,1.0); 
} 

我在上面一行錯誤的錯誤:房產UnityEngine.Component.constantForce錯誤:屬性「UnityEngine.Component.constantForce」只有在統一的MonoDevelop讀

讀我想創建地形Materix和應用ConstantForce在他們身上,讓他們移動。我需要Materix,因爲我想重用它們並創建EndLess Envirnoment,讓它們移動。 我嘗試和遇到錯誤在這條線:

_terrainGrid[X,Y].transform.constantForce = Vector3(0,0,1.0); 

錯誤:

Property 'UnityEngine.Component.constantForce' is read only 

回答

0

嘗試使用:

ConstantForce.relativeForce = Vector3(0, 0, 1.0); 

constantForce.relativeForce代表力,相對於剛體座標系,應用到每一幀。