Unity中实现飞机姿态表的功能显示


前言

最近项目中需要做个设备的姿态表,用来表示自身的俯仰滚动角,于是仿照飞机的飞机姿态表做了一个功能事宜。


一、使用步骤

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);
        }

    }
}

总结

功能比较简单,使用起来比较方便。

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值