当前位置:网站首页>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);
}
}
}
边栏推荐
- Unity脚本常用API Day03
- CentOS 6.3 下 PHP编译安装JSON模块报错解决
- The per capita savings of major cities in China have been released. Have you reached the standard?
- What are the concepts of union, intersection, difference and complement?
- MySQL learning notes - data type (numeric type)
- [differential privacy and data adaptability] differential privacy code implementation series (XIV)
- LeetCode 58. 最后一个单词的长度
- .Net 应用考虑x64生成
- 找数字
- 2022年九大CIO趋势和优先事项
猜你喜欢
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
从0到1建设智能灰度数据体系:以vivo游戏中心为例
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
Is BigDecimal safe to calculate the amount? Look at these five pits~~
Preliminary exploration of flask: WSGI
[Dalian University of technology] information sharing of postgraduate entrance examination and re examination
近一亿美元失窃,Horizon跨链桥被攻击事件分析
Halcon knowledge: NCC_ Model template matching
Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
C1 certification learning notes 3 -- Web Foundation
随机推荐
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
输入宽度!
宽度精度
這幾年爆火的智能物聯網(AIoT),到底前景如何?
%s格式符
On the implementation plan of MySQL explain
小数,指数
左右对齐!
Helix Swarm中文包发布,Perforce进一步提升中国用户体验
进制形式
Helix swarm Chinese package is released, and perforce further improves the user experience in China
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
深度学习 网络正则化
宽度与对齐
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
这几年爆火的智能物联网(AIoT),到底前景如何?
Unity动画Animation Day05
Korean AI team plagiarizes shock academia! One tutor with 51 students, or plagiarism recidivist
Ffmpeg Visual Studio development (IV): audio decoding