unity基础(GameObject transform)

unity基础(GameObject transform),第1张

GameObject是unity所有实体的基类

常用的函数

1GameObjectFind(“Cube”);

可以查找并获取一个指定的name为Cube的对象。然后进行其他 *** 作。

2GameObjectFindWithTag(“_cube");

和Find函数相似,不同之处在于该方法是通过标签(tag)值查找

3GameObjectSetActive(true);

激活/停用此游戏对象(如下图11所示打钩(true)的时候该游戏对象就属于激活状态,去掉打钩(false)就属于停用状态即游戏对象也就不会显示在你的视野内)

4GameObjectGetComponent

获取组件:如果这个游戏对象附件了一个type名称类型的组件,则返回该组件,否则为空。

hinge=gameObjectGetComponent("HingeJoint")asHingeJoint;

hingeuseSpring=false;

是一个每个对象都用的组件,用于储存并 *** 控物体的位置、旋转和缩放。(每一个Transform可以有一个父级,允许你分层次应用位置、旋转和缩放。可以在Hierarchy面板查看层次关系。他们也支持计数器(enumerator),因此你可以使用循环遍历子对象。)

1transformFind

是通过名字查找到子对象并返回他。

2TransformTranslate  平移

向莫一个方向进行移动多少的距离

移动变换由x沿着x轴,y沿着y轴,z沿着z轴

transformTranslate(0,0, TimedeltaTime);

transformTranslate(0, TimedeltaTime,0, SpaceWorld);

3Transformparent

通过该方法可以找到父对象,然后可以进行对父对象 *** 作(如改变父对象名字)

_childgameObjecttransformparentgameObjectname = "ParentBox";

4Transformroot

返回最根部父类进行 *** 作

string name=_childgameObjecttransformrootgameObjectname;

DebugLog(name);

5Transformposition

在世界坐标系中transform的·位置

6Transformrotation

Unity以四元数储存旋转角度。要旋转一个对象使用TransformRotate,使用TransformeulerAngles以欧拉角设置旋转角度。

7TransformlocalScale

相对于父级对象进行缩放(局部缩放)

transformlocalScale = new Vector3(05f,05f, 05f);

(为=时是对该物体进行缩小到后面参数的大小,+=时是对该物体进行放大)

8Transformforward

向前在世界空间坐标,变换的蓝色轴。也就是z轴。

在世界空间坐标,变换的蓝色轴。也就是z轴。

void updateCameraVectors() { // Calculate the new Front vector glm::vec3 front; frontx = cos(glm::radians(this->Yaw)) cos(glm::radians(this->Pitch)); fronty = sin(glm::radians(this->Pitch)); frontz = sin(glm::radians(this->Yaw)) cos(glm::radians(this->Pitch)); this->Front = glm::normalize(front); // Also re-calculate the Right and Up vector }

0)

Vector3 rotationVector3 = new Vector3(0f, 30f, 0f)rotation = rotation;/将transform中的rotation修改成(0,30Euler(rotationVector3);

transform;

Quaternion rotation = Quaternion:

具体使用代码如下

var distance:Number = 50;

var a:Number = 0;

thisaddEventListener(EventENTER_FRAME, enterFrameHandller);

function enterFrameHandller(event:Event):void

{

目标x = 中心点x + distance Mathcos(a MathPI / 180);

目标y = 中心点y + distance Mathsin(a MathPI / 180);

a+= 10;

以上就是关于unity基础(GameObject transform)全部的内容,包括:unity基础(GameObject transform)、Unity中如何获取指定角度的方向向量、unity3d 如何将rotation改为0等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9572468.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存