playMaker

Author Topic: The following code example can be implemented as a playmaker?  (Read 1863 times)

choi

  • Playmaker Newbie
  • *
  • Posts: 40
The following code example can be implemented as a playmaker?
This is the code to figure out the texture of the terrain.
Code: [Select]
using UnityEngine;

public class PlayerHitCheck : MonoBehaviour
{

private TerrainData terrainData;
private Vector3 terrainPos;
private string resultText;

void Start ()
{
terrainData = Terrain.activeTerrain.terrainData;
terrainPos = Terrain.activeTerrain.transform.position;
}

float textureIndex1;
float textureIndex2;

void Update(){

int mapX = Mathf.RoundToInt(((transform.position.x - terrainPos.x) / terrainData.size.x) * terrainData.alphamapWidth);
int mapZ = Mathf.RoundToInt(((transform.position.z - terrainPos.z) / terrainData.size.z) * terrainData.alphamapHeight);


float[,,] splatmapData = terrainData.GetAlphamaps(mapX, mapZ, 1, 1);

textureIndex1 = splatmapData[0,0,0]; //grass texture
textureIndex2 = splatmapData[0,0,1]; //sand texture

resultText = " grass  : "+textureIndex1+"\n sand : "+textureIndex2;


}

void OnGUI(){
GUI.BeginGroup (new Rect (10, 10, 200, 40));
GUI.Box(new Rect (0, 0, 200, 40),resultText);
GUI.EndGroup ();
}


}