35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class PlayerSpeedChecker : MonoBehaviour
|
|
{
|
|
public float rayDistance = 10f;
|
|
public float raycastHeightOffset = 3f;
|
|
public TMP_Text speedText;
|
|
|
|
void Update()
|
|
{
|
|
Vector3 rayOrigin = transform.position + Vector3.up * raycastHeightOffset;
|
|
Vector3 rayDirection = transform.forward;
|
|
|
|
// ³çóàë³çàö³ÿ Ray
|
|
Debug.DrawRay(rayOrigin, rayDirection * rayDistance, Color.red);
|
|
|
|
// Raycast
|
|
if (Physics.Raycast(rayOrigin, rayDirection, out RaycastHit hit, rayDistance))
|
|
{
|
|
GameObject go = hit.collider.gameObject;
|
|
PlayerMovement pm = go.GetComponent<PlayerMovement>();
|
|
if (pm != null)
|
|
{
|
|
if (Lesson1Controller.Instance.activeExperiment == 1) speedText.text = "Speed: " + pm.playerSpeed.ToString("F0");
|
|
else speedText.text = "???";
|
|
}
|
|
|
|
} else
|
|
{
|
|
speedText.text = "";
|
|
}
|
|
}
|
|
}
|