mirror of
https://github.com/DerTyp7/fps-citybuild-unity.git
synced 2025-10-29 20:22:08 +01:00
Added TerrainGenerator (Hit Terrain y))
This commit is contained in:
8
Assets/Scripts/NPC.meta
Normal file
8
Assets/Scripts/NPC.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cbe760ab4339094882e9b35d42a7d39
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Scripts/NPC/TerrainGenerator.cs
Normal file
40
Assets/Scripts/NPC/TerrainGenerator.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/NPC/TerrainGenerator.cs.meta
Normal file
11
Assets/Scripts/NPC/TerrainGenerator.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f1735c997ccb39408dfa8bf3790319f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user