前言
最近项目中需要做个设备的姿态表,用来表示自身的俯仰滚动角,于是仿照飞机的飞机姿态表做了一个功能事宜。
一、使用步骤
1.导入资源
具体资源表都已经上传到个人资源文件了。
https://download.csdn.net/download/ForKnowledgeMe/89579447
2.设置数据
设置角度
操作效果
/*
*FileName: AttitudeInstrumentControl.cs
*Author: 杰尼杰尼丶
*Date: 2024/07/24 13:22:25
*UnityVersion: 2021.3.3f1
*Description: 姿态表控制
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AttitudeInstrumentControl : MonoBehaviour
{
/// <summary>
/// 俯仰
/// </summary>
public GameObject PitchAngleObj;
public float PitchAngleValue;
public const float const_pitchAngleRatio = -7f;
/// <summary>
/// 滚动
/// </summary>
public GameObject RollAngleObj;
public float RollAngleValue;
public const float const_rollAngleRatio = -1f;
[HideInInspector]
public float Speed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (RollAngleObj)
{
RollAngleObj.transform.localRotation = Quaternion.Slerp(RollAngleObj.transform.localRotation, Quaternion.Euler(new Vector3(0, 0, const_rollAngleRatio * RollAngleValue)), Time.deltaTime* Speed);
}
if (PitchAngleObj)
{
PitchAngleObj.transform.localPosition =Vector3.Lerp(PitchAngleObj.transform.localPosition,new Vector3(-2.1f, const_pitchAngleRatio * PitchAngleValue, 0) ,Time.deltaTime * Speed);
}
}
}
总结
功能比较简单,使用起来比较方便。