- Home /
Terrain edit on multiplayer
i have a terrain editor that can raise the terrain on mouse click. however i tried this on a multiplayer network, and i can only see the terrain change on the host i added networkview on the terrain, so i don't know what's wrong this is the script that i have attached to the terrain using UnityEngine; using System.Collections;
public class TerrainEdit : MonoBehaviour
{
public Terrain myTerrain;
int xResolution;
int zResolution;
float[,] heights;
void Start()
{
xResolution = myTerrain.terrainData.heightmapWidth;
zResolution = myTerrain.terrainData.heightmapHeight;
heights = myTerrain.terrainData.GetHeights(0,0,xResolution,zResolution);
}
void Update()
{
if(Input.GetMouseButton(1))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
raiseTerrain(hit.point);
myTerrain.Flush();
}
}
}
private void raiseTerrain(Vector3 point)
{
int terX =(int)((point.x / myTerrain.terrainData.size.x) * xResolution);
int terZ =(int)((point.z / myTerrain.terrainData.size.z) * zResolution);
float y = heights[terX,terZ];
y += 0.0005f;
if (y > 1)
y = 1;
float[,] height = new float[1,1];
height[0,0] = y;
heights[terX,terZ] = y;
myTerrain.terrainData.SetHeights(terX, terZ, height);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiplayer game, terrain edit control for 2 characters 0 Answers
Dealing damage over a network 1 Answer
Do i need to have 2 seperate apps communicating for server/client relationship? 2 Answers
Any way to change terrain standard size? 1 Answer
set otherplayer as master client when master client leaves room photon 1 Answer