当前位置:网站首页>Unity script API - transform transform
Unity script API - transform transform
2022-07-04 15:22:00 【@Night Charm】
Every object in the scene has a Transform. Used to store and control the position of objects 、 Rotate and scale . every last Transform You can have a parent , Allows you to apply location hierarchically 、 Rotate and scale . Can be in Hierarchy Panel view hierarchy . They also support counters (enumerator), So you can loop through sub objects .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Transfrom Provides search ( Father 、 root 、 Son ) Transform component functions 、 Change position 、 angle 、 Size function
/// </summary>
public class TransfromDemo : MonoBehaviour
{
public Transform tf;
private void OnGUI()
{
if (GUILayout.Button("foreach -- transfrom"))
{
// Every object in the scene has a Transfrom, Used to store and manipulate the position of objects 、 rotate 、 The zoom .
// every last Transfrom You can have a parent , Allows you to apply location hierarchically 、 Rotate and scale .
// Can be in Hierarchy Panel view hierarchy . They also support calculators , So you can loop through sub objects
foreach (Transform child in this.transform)
{
//child Transform components for each sub object
print(child.name);
}
}
if (GUILayout.Button("root"))
{
// Get the root object transformation component
Transform rootTF = this.transform.root;
Debug.Log(rootTF.name);
}
if (GUILayout.Button("parent"))
{
// Get the parent object transformation component
Transform parentTF = this.transform.parent;
Debug.Log(parentTF.name);
}
if (GUILayout.Button("Setparent"))
{
// Set parent
// The position of the current object As world coordinates position
//this.transform.SetParent(tf,true);
// The position of the current object As localPosition
this.transform.SetParent(tf,false);
}
if (GUILayout.Button("Find"))
{
// Get sub objects by name
Transform tf = this.transform.Find(" Sub object name ");
Debug.Log(tf.name);
Transform tf1 = this.transform.Find(" Sub object name / Sub object name ");
Debug.Log(tf1.name);
}
if (GUILayout.Button("GetChild"))
{
int count = this.transform.childCount;
// Get sub objects according to the index Cannot acquire grandchildren objects
for (int i = 0;i < count;i++)
{
Transform childTf = this.transform.GetChild(i);
}
}
// practice : Find sub objects when the level is unknown
if (GUILayout.Button("pos / scale"))
{
// The position of an object relative to the origin of the world coordinate system
//this.transform.position;
// The position of the object relative to the pivot point of the parent object
//this.transform.localPosition;
// Scale relative to parent 1 2 1
//this.transform.localScale;
// Understood as a : Scale the object to the model ( Self scaling * Scale of parent object )
//this.transfrom.lossyScale
// Such as : The parent object localScale by 3 Current object localScale by 2
// lossyScale Then for 6
}
if (GUILayout.Button("Translate"))
{
// To its own coordinate system Z Axis Move 1 rice
this.transform.Translate(0, 0, 1);
// To the world coordinate system Z Axis Move 1 rice
//this.transform.Translate(0, 0, 1, Space.World);
}
if (GUILayout.Button("Rotate"))
{
// To its own coordinate system y Axis rotate 10 degree
//this.transform.Rotate(0, 10, 0);
// To the world coordinate system y Axis rotate 10 degree
this.transform.Rotate(0, 10, 0, Space.World);
}
if (GUILayout.RepeatButton("RotateAround"))
{
// To the world coordinate system Around the y Shaft rotation
transform.RotateAround(Vector3.zero, Vector3.up, 1);
}
}
}
边栏推荐
- 中国主要城市人均存款出炉,你达标了吗?
- 【读书会第十三期】 音频文件的封装格式和编码格式
- flutter 报错 No MediaQuery widget ancestor found.
- [differential privacy and data adaptability] differential privacy code implementation series (XIV)
- Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
- 2022 financial products that can be invested
- c# 实现定义一套中间SQL可以跨库执行的SQL语句
- 怎么判断外盘期货平台正规,资金安全?
- Flutter reports an error no mediaquery widget ancestor found
- Ffmpeg Visual Studio development (IV): audio decoding
猜你喜欢

When synchronized encounters this thing, there is a big hole, pay attention!

Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作

LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04

Ffmpeg Visual Studio development (IV): audio decoding

科普达人丨一文看懂阿里云的秘密武器“神龙架构”

TechSmith Camtasia studio 2022.0.2 screen recording software
![[Dalian University of technology] information sharing of postgraduate entrance examination and re examination](/img/06/df5a64441814c9ecfa2f039318496e.jpg)
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination

2022年九大CIO趋势和优先事项

近一亿美元失窃,Horizon跨链桥被攻击事件分析

Preliminary exploration of flask: WSGI
随机推荐
Redis 發布和訂閱
Preliminary exploration of flask: WSGI
web聊天室实现
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
Redis shares four cache modes
Halcon knowledge: NCC_ Model template matching
%s格式符
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
selenium 浏览器(2)
Unity预制件Prefab Day04
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
怎么判断外盘期货平台正规,资金安全?
%f格式符
Redis的4种缓存模式分享
[differential privacy and data adaptability] differential privacy code implementation series (XIV)
Weibo and Huya advance into interest communities: different paths for peers
Usage of database functions "recommended collection"
PXE网络