unityzgy/Assets/ThirdPackages/VRPackage/VRTK/Examples/ExampleResources/Scripts/RC_Car.cs
ayuan9957 bf12e02276 feat: 多语言本地化系统 - 支持中/英/法/俄实时切换
- LocalizationManager: 新增翻译表(SetFormatted/SetDuration/LocalizeOperateMsg)
- LoginPanel: InputField placeholder本地化、字体颜色保持
- HistoryPanel: 用时数据本地化、placeholder本地化
- RecordDetailPanel: 操作详情消息本地化(LanguageChanged重建)
- AppraiseWindowBase: 评价等级本地化、操作消息重建
- EditorAppraiser: 所有评估消息改用InjectOperateMsgLocalized
- StudentOperateRecorder: 新增InjectOperateMsgLocalized方法
- LocalizationLanguageTestBar: 单例模式、ScreenSpaceOverlay筛选
- 字体切换时保留颜色和verticalOverflow
2026-07-16 10:05:59 +08:00

117 lines
3.0 KiB
C#

namespace VRTK.Examples
{
using UnityEngine;
public class RC_Car : MonoBehaviour
{
public float maxAcceleration = 3f;
public float jumpPower = 10f;
private float acceleration = 0.05f;
private float movementSpeed = 0f;
private float rotationSpeed = 180f;
private bool isJumping = false;
private Vector2 touchAxis;
private float triggerAxis;
private Rigidbody rb;
private Vector3 defaultPosition;
private Quaternion defaultRotation;
public void SetTouchAxis(Vector2 data)
{
touchAxis = data;
}
public void SetTriggerAxis(float data)
{
triggerAxis = data;
}
public void ResetCar()
{
transform.position = defaultPosition;
transform.rotation = defaultRotation;
}
private void Awake()
{
rb = GetComponent<Rigidbody>();
defaultPosition = transform.position;
defaultRotation = transform.rotation;
}
private void FixedUpdate()
{
if (isJumping)
{
touchAxis.x = 0f;
}
CalculateSpeed();
Move();
Turn();
Jump();
}
private void CalculateSpeed()
{
if (touchAxis.y != 0f)
{
movementSpeed += (acceleration * touchAxis.y);
movementSpeed = Mathf.Clamp(movementSpeed, -maxAcceleration, maxAcceleration);
}
else
{
Decelerate();
}
}
private void Decelerate()
{
if (movementSpeed > 0)
{
movementSpeed -= Mathf.Lerp(acceleration, maxAcceleration, 0f);
}
else if (movementSpeed < 0)
{
movementSpeed += Mathf.Lerp(acceleration, -maxAcceleration, 0f);
}
else
{
movementSpeed = 0;
}
}
private void Move()
{
Vector3 movement = transform.forward * movementSpeed * Time.deltaTime;
rb.MovePosition(rb.position + movement);
}
private void Turn()
{
float turn = touchAxis.x * rotationSpeed * Time.deltaTime;
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
rb.MoveRotation(rb.rotation * turnRotation);
}
private void Jump()
{
if (!isJumping && triggerAxis > 0)
{
float jumpHeight = (triggerAxis * jumpPower);
rb.AddRelativeForce(Vector3.up * jumpHeight);
triggerAxis = 0f;
}
}
private void OnTriggerStay(Collider collider)
{
isJumping = false;
}
private void OnTriggerExit(Collider collider)
{
isJumping = true;
}
}
}