资源简介
本资源是我关于官方资源Standard Assets -->Vehicles-->Car中车的主控脚本CarController.cs的个人全注释,及一些心得,我当时觉得这个脚本中有一些属性不是很理解,于是做了分析。希望能帮到有需要的朋友
代码片段和文件信息
using System;
using UnityEngine;
namespace UnityStandardAssets.Vehicles.Car
{
//汽车驱动类型
internal enum CarDriveType
{
//四驱
FrontWheelDrive
//后驱
RearWheelDrive
//前驱
FourWheelDrive
}
//速度类型
internal enum SpeedType
{
//英里每小时
MPH
//千米每小时
KPH
}
public class CarController : MonoBehaviour
{
[SerializeField] private CarDriveType m_CarDriveType = CarDriveType.FourWheelDrive;
[SerializeField] private WheelCollider[] m_WheelColliders = new WheelCollider[4];
[SerializeField] private Gameobject[] m_WheelMeshes = new Gameobject[4];
[SerializeField] private WheelEffects[] m_WheelEffects = new WheelEffects[4];
//重心位置
[SerializeField] private Vector3 m_CentreOfMassOffset;
//最大可转角度
[SerializeField] private float m_MaximumSteerAngle;
[Range(0 1)] [SerializeField] private float m_SteerHelper; // 0 is raw physics 1 the car will grip in the direction it is facing
[Range(0 1)] [SerializeField] private float m_TractionControl; // 0 is no traction control 1 is full interference
//所有轮胎的扭矩
[SerializeField] private float m_FullTorqueOverAllWheels;
//反向扭矩
[SerializeField] private float m_ReverseTorque;
//最大刹车扭矩
[SerializeField] private float m_MaxHandbrakeTorque;
//最大下压力
[SerializeField] private float m_Downforce = 100f;
//速度单位
[SerializeField] private SpeedType m_SpeedType;
//最高速度
[SerializeField] private float m_Topspeed = 200;
//档位总数
[SerializeField] private static int NoOfGears = 5;
//
[SerializeField] private float m_RevRangeBoundary = 1f;
//最大滑动距离
[SerializeField] private float m_SlipLimit;
//刹车扭矩
[SerializeField] private float m_BrakeTorque;
private Quaternion[] m_WheelMeshLocalRotations;
private Vector3 m_Prevpos m_Pos;
private float m_SteerAngle;
//当前档位
private int m_GearNum;
//档位因子
private float m_GearFactor;
//上一帧汽车方向
private float m_OldRotation;
//当前扭矩
private float m_CurrentTorque;
private Rigidbody m_Rigidbody;
private const float k_ReversingThreshold = 0.01f;
public bool Skidding { get; private set; }
public float BrakeInput { get; private set; }
public float CurrentSteerAngle{ get { return m_SteerAngle; }}
public float CurrentSpeed{ get { if(m_Rigidbody == null) return 0;return m_Rigidbody.velocity.magnitude*2.23693629f; }}
public float MaxSpeed{get { return m_Topspeed; }}
public float Revs { get; private set; }
public float AccelInput { get; private set; }
public Rigidbody CarRigidbody { get{return m_Rigidbody;}}
// Use this for initialization
private void Start()
{
//四个轮胎的自转方向
m_WheelMeshLocalRotations = new Quaternion[4];
for (int i = 0
- 上一篇:C#开发大全提高卷随书光盘
- 下一篇:餐饮点餐系统实验报告
相关资源
- 愤怒的小鸟unity3d279320
- PureMVC for Unity3d Demo
- Unity3dMYO肌电臂环二次开发例程(保证
- Unity 3D Paint in 3D 最新版(1.56)
- Unity3D应用嵌入到WPF应用
- WinForm嵌入Unity3D并实现交互
- unity3d小游戏,见缝插针2d
- Unity3D NGUI Next Gen UI 最新版插件
- Unity 2D横版冒险跳跃游戏 带源码
- unity3d 登录注册界面功能实现 c#
- unity3d创意的手机消除游戏源码
- unity3D赛车游戏项目源代码
- Unity3D脚本编程 使用C#语言开发跨平台
- RealSky Unity3d实时动态天空球插件
- Unity in Action Multiplatform game development
- Unity3d开发案例(坦克克星游戏,C#版
- Unity3D与Winform交互
- CubeAttitudeShow.zip
- Unity3D射击游戏《全民飞机大战》源码
- Unity3D飞机大战
- unity3d2018插件NGUI
- unity3D外星风格射击游戏完整项目源码
- unity3D神启全套源码资源
- Unity3D脚本编程 使用C#语言开发跨平台
- unity3d多人联机赛车游戏完整源码
- Unity 3D脚本编程——使用C#语言开发跨
- Unity3D 街机捕鱼游戏源码
- Unity3D《farm business》农场模拟经营游戏
- 手把手教你用C#制作RPG游戏__罗培羽著
- Socket网络模块Unity c#
评论
共有 条评论