RequireComponent需要组件与Quaternion 四元数

1.第一人称人物身上应该有Rigidbody刚体组件和CapsuleCollider胶囊体组件,要判断有没有,如果没有要进行添加,

这里就用到了RequireComponent组件,[RequireComponent(typeof(Rigidbody))]

[RequireComponent(typeof(CapsuleCollider))]  

Inherits from Attribute

The RequireComponent attribute lets automatically add required component as a dependency.

RequireComponent 属性可以允许自动添加需要的组件作为一个附属。

个人理解为如果游戏对象身上没有这个组件 ,就会加上这个组件。

When you add a script which uses RequireComponent, the required component will automatically be added to the game object. This is useful to avoid setup errors. For example a script might require that a rigid body is always added to the same game object. Using  RequireComponen  this will be done automatically, thus you can never get the setup wrong.

当你添加的一个用了RequireComponent 组件的脚本,需要的组件将会自动被添加到game object(游戏物体)。这个可以有效的避免组装错误。举个例子一个脚本可能需要刚体总是被添加在相同的game object(游戏物体)上。用RequireComponent 属性的话,这个过程将被自动完成,因此你可以永远不会犯组装错误

2.Quaternion四元数

用于表示旋转。不会出现万向节锁并且能够很容易被插值。Unity中使用Quaternion表示所有旋转。

使用方法如下(部分代码):

private Transform  m_chaTrans;

private Quaternion quaternion;

quaternion = m_chaTrans.rotation;

quaternion *= Quaternion.Euler(0f,1f,0f);


欧拉角:

m_chaRotate = m_chaTrans.eulerAngles;

m_chaRotate += new Vector3(0f,1f,0f);







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值