人生如白驹过隙,忽然而已|

云鲸啊

园龄:3年5个月粉丝:5关注:4

unity学习笔记(1)

1.想要物体被重力影响则需为其加入刚体组件 RigIdbody
2.如果想要两个类绑定的话,最简单方便的方法是创建一个public gameobject类,在unity界面绑定对应的物体。
3.Vector3三维向量:表示3D的向量和点。包含位置、方向(朝向)、欧拉角的信息,也包含做些普通向量运算的函数。
4.Transform类
成员变量:
position:在世界空间坐标transform的位置。
localPosition:相对于父级的变换的位置。如果该变换没有父级,那么等同于Transform.position。
eulerAngles:世界坐标系中的旋转(欧拉角)。
localEulerAngles:相对于父级的变换旋转角度。
right:世界坐标系中的右方向。(世界空间坐标变换的红色轴。也就是x轴。)
up:世界坐标系中的上方向。(在世界空间坐标变换的绿色轴。也就是y轴。)
forward:世界坐标系中的前方向。(在世界空间坐标变换的蓝色轴。也就是z轴。)
rotation:世界坐标系中的旋转(四元数)。
localRotation:相对于父级的变换旋转角度。
localScale:相对于父级的缩放比例。
parent:父对象Transform组件。
worldToLocalMatrix:矩阵变换的点从世界坐标转为自身坐标(只读)。
localToWorldMatrix:矩阵变换的点从自身坐标转为世界坐标(只读)。
root:对象层级关系中的根对象的Transform组件。
childCount:子对象数量。
lossyScale:全局缩放比例(只读)。
成员方法:
1)Translate,用来移动物体的函数,非常常用的一个函数。
public void Translate (translation : Vector3, relativeTo : Space = Space.Self) : void
把物体向translation方向移动,距离为translation.magnitude。 relativeTo表示这个移动的参考坐标系。

public void Translate (x : float, y : float, z : float, relativeTo : Space = Space.Self) : void
同上

public void Translate (translation : Vector3, relativeTo : Transform) : void
如果relativeTo 不是null,则以目标物体relativeTo的自身轴向作为参考坐标系。

public void Translate (x : float, y : float, z : float, relativeTo : Transform) : void
同上

脚本:

var speed=30;

//将物体以30米每秒的速度向前移动。

trasform.Translate(Vector3.forwardspeedTime.deltaTime);

2)Rotate,用来旋转物体的函数,非常常用,在知道需要旋转的角度的情况下。如果要让物体旋转到指定位置,需要搭配Quaternion来使用。
public void Rotate (eulerAngles : Vector3, relativeTo : Space = Space.Self) : void
旋转eulerAngles度(3个轴向分别旋转),以relativeTo为参考坐标系

public void Rotate (xAngle : float, yAngle : float, zAngle : float, relativeTo : Space = Space.Self) : void
同上

public void Rotate (axis : Vector3, angle : float, relativeTo : Space = Space.Self) : void
以axis为轴旋转angle度,以relativeTo为参考坐标系

3)RotateAround 让物体以某一点为轴心成圆周运动。
public void RotateAround (point : Vector3, axis : Vector3, angle : float) : void
让物体以point为中心,绕axis为轴向旋转angle度。保持原来与point的距离。

4)LookAt 让物体的z轴看向目标物体
public void LookAt (target : Transform, worldUp : Vector3 = Vector3.up) : void
让物体的z轴看向target的位置,并以worldUp为y轴指向方向。

public void LookAt (worldPosition : Vector3, worldUp : Vector3 = Vector3.up) : void
让物体看向worldPosition

5)TransformDirection
public Vector3 TransformDirection (direction : Vector3) : Vector3
返回以物体自身为坐标轴的向量direction在世界坐标中的朝向向量。

public Vector3 TransformDirection (x : float, y : float, z : float) : Vector3
同上

6)InverseTransformDirection
public Vector3 InverseTransformDirectionTransformDirection (direction : Vector3) : Vector3
public Vector3 InverseTransformDirectionTransformDirection (x : float, y : float, z : float) : Vector3
与TransformDirection相反,从世界坐标转换到自身相对坐标。

7)TransformPoint
public Vector3 TransformPoint (position : Vector3) : Vector3
public Vector3 TransformPoint (x : float, y : float, z : float) : Vector3
把一个点从自身相对坐标转换到世界坐标

8)InverseTransformPoint
public Vector3 InverseTransformPoint (position : Vector3) : Vector3
public Vector3 InverseTransformPoint (x : float, y : float, z : float) : Vector3
把一个点从时间坐标转换到自身坐标的位置。

9)DetachChildren
public void DetachChildren () : void
把自身所有的子物体的父物体都设成世界,也就是跟自己的所有子物体接触父子关系。

10)Find
public Transform Find (name : string) : Transform
找到一个名字是name的物体并返回

如果没有找到则返回null。如果字符串被/隔离,函数则会像文件路径一样逐级下查。

// The magical rotating finger
function Update() {
aFinger = transform.Find("LeftShoulder/Arm/Hand/Finger");
aFinger.Rotate(Time.deltaTime*20, 0, 0);
}

11)IsChildOf
public bool IsChildOf (parent : Transform) : bool
如果物体是parent的父子层级关系下的一员,返回true;

本文作者:云鲸啊

本文链接:https://www.cnblogs.com/yunjing/p/15839360.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   云鲸啊  阅读(72)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 ocean eyes bili
ocean eyes - bili
00:00 / 00:00
An audio error has occurred.

作词 : Finneas O'Connell

作曲 : Finneas O'Connell

I've been watching you

For some time

Can't stop staring

At those ocean eye

Burning cities

And napalm skies

Fifteen flares inside those ocean eyes

Your ocean eyes

No fair

You really know how to make me cry

When you give me those ocean eyes

I'm scared

I've never fallen from quite this high

Falling into your ocean eyes

Those ocean eyes

I've been walking through

A world gone blind

Can't stop thinking of your diamond mind

Can't stop thinking of your diamond mind

Careful creature

Careful creature

Made friends with time

He left her lonely with a diamond mind

He left her lonely with a diamond mind

And those ocean eyes

And those ocean eyes

No fair

You really know how to make me cry

You really know how to make me cry

When you give me those ocean eyes

I'm scared

I've never fallen from quite this high

I've never fallen from quite this high

Falling into your ocean eyes

Those ocean eyes

Those ocean eyes

No fair

No fair

You really know how to make me cry

You really know how to make me cry

When you give me those ocean eyes

I'm scared

I'm scared

I've never fallen from quite this high

I've never fallen from quite this high

Falling into your ocean eyes

Those ocean eyes

Those ocean eyes