init commit
This commit is contained in:
34
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs
Normal file
34
Assets/Scripts/Lesson_1/PlayerSpeedChecker.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
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 = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user