Added TerrainGenerator (Hit Terrain y))

This commit is contained in:
DerTyp187
2021-10-01 10:41:11 +02:00
parent 15203c52ad
commit 8692827990
4 changed files with 80 additions and 0 deletions

8
Assets/Scripts/NPC.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3cbe760ab4339094882e9b35d42a7d39
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TerrainGenerator : MonoBehaviour
{
public (float y, bool isTerrain) GetTerrainHit(float x, float z)
{
float y = 0;
bool isTerrain = false;
Vector3 position = new Vector3(x, 50, z);
RaycastHit hit;
if(Physics.Raycast(position, Vector3.down, out hit, Mathf.Infinity))
{
if(hit.transform.tag == "Terrain")
{
Debug.Log("Terrain Hit");
y = hit.point.y;
Debug.Log(hit.point.y);
isTerrain = true;
}
else
{
y = hit.point.y;
}
}
else
{
Debug.Log("Terrain not Hit");
}
return (y, isTerrain);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f1735c997ccb39408dfa8bf3790319f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: