当前位置:网站首页>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);
}
}
}
边栏推荐
- 案例分享|金融业数据运营运维一体化建设
- Helix swarm Chinese package is released, and perforce further improves the user experience in China
- 深入JS中几种数据类型的解构赋值细节
- Redis哨兵模式实现一主二从三哨兵
- In today's highly integrated chips, most of them are CMOS devices
- PXE network
- Ffprobe common commands
- [learning notes] matroid
- LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
- Redis 发布和订阅
猜你喜欢

Unity动画Animation Day05

Data Lake Governance: advantages, challenges and entry

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

微博、虎牙挺进兴趣社区:同行不同路

31年前的Beyond演唱会,是如何超清修复的?

Ffprobe common commands
Redis哨兵模式实现一主二从三哨兵

AI has surpassed Dr. CS in question making?
MySQL组合索引(多列索引)使用与优化案例详解

Deep learning neural network case (handwritten digit recognition)
随机推荐
中国主要城市人均存款出炉,你达标了吗?
MySQL学习笔记——数据类型(2)
What are the concepts of union, intersection, difference and complement?
从0到1建设智能灰度数据体系:以vivo游戏中心为例
每周招聘|高级DBA年薪49+,机会越多,成功越近!
Unity update process_ Principle of unity synergy
文本挖掘工具的介绍[通俗易懂]
Optimization method of deep learning neural network
Hexadecimal form
An article learns variables in go language
LeetCode 58. 最后一个单词的长度
I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
深入JS中几种数据类型的解构赋值细节
Implementation of web chat room
函数式接口,方法引用,Lambda实现的List集合排序小工具
numpy笔记
左右对齐!
flutter 报错 No MediaQuery widget ancestor found.
How to handle exceptions in multithreading?
Decimal, exponential