65 lines
1.1 KiB
C#
65 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class RodSupportCheckGround : MonoBehaviour
|
|
{
|
|
public bool hideOutlines;
|
|
|
|
public bool isTerrain;
|
|
|
|
public Vector3 dropPoint;
|
|
|
|
public Outline[] outlines;
|
|
|
|
private void Start()
|
|
{
|
|
if (outlines.Length == 0)
|
|
{
|
|
outlines = GetComponentsInChildren<Outline>();
|
|
}
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
CheckGroundByRaycasting();
|
|
if (hideOutlines)
|
|
{
|
|
for (int i = 0; i < outlines.Length; i++)
|
|
{
|
|
outlines[i].enabled = false;
|
|
}
|
|
return;
|
|
}
|
|
for (int j = 0; j < outlines.Length; j++)
|
|
{
|
|
if (!isTerrain)
|
|
{
|
|
outlines[j].enabled = true;
|
|
outlines[j].OutlineColor = Color.red;
|
|
}
|
|
else
|
|
{
|
|
outlines[j].enabled = true;
|
|
outlines[j].OutlineColor = Color.green;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CheckGroundByRaycasting()
|
|
{
|
|
isTerrain = false;
|
|
dropPoint = Vector3.zero;
|
|
if (Physics.Raycast(base.transform.position, -Vector3.up, out var hitInfo, 2f))
|
|
{
|
|
switch (hitInfo.transform.tag)
|
|
{
|
|
case "Bridge":
|
|
case "Terrain":
|
|
case "Stone":
|
|
isTerrain = true;
|
|
dropPoint = hitInfo.point;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|