当前位置:网站首页>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);
}
}
}
边栏推荐
- [learning notes] matroid
- PXE network
- 找数字
- What are the concepts of union, intersection, difference and complement?
- [local differential privacy and random response code implementation] differential privacy code implementation series (13)
- Unity脚本常用API Day03
- Unity脚本API—GameObject游戏对象、Object 对象
- 力扣刷题01(反转链表+滑动窗口+LRU缓存机制)
- Summer Review, we must avoid stepping on these holes!
- Numpy notes
猜你喜欢
Preliminary exploration of flask: WSGI
MySQL学习笔记——数据类型(数值类型)
这几年爆火的智能物联网(AIoT),到底前景如何?
函数式接口,方法引用,Lambda实现的List集合排序小工具
【大连理工大学】考研初试复试资料分享
Ffmpeg Visual Studio development (IV): audio decoding
Guitar Pro 8win10最新版吉他学习 / 打谱 / 创作
Luo Gu - some interesting questions
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Redis哨兵模式实现一主二从三哨兵
随机推荐
进制形式
[local differential privacy and random response code implementation] differential privacy code implementation series (13)
Is BigDecimal safe to calculate the amount? Look at these five pits~~
LeetCode 58. Length of the last word
产品好不好,谁说了算?Sonar提出分析的性能指标,帮助您轻松判断产品性能及表现
Redis sentinel mode realizes one master, two slave and three Sentinels
压力、焦虑还是抑郁? 正确诊断再治疗
进制乱炖
How to build a technical team that will bring down the company?
selenium 浏览器(2)
Width and alignment
Flutter reports an error no mediaquery widget ancestor found
一篇文章搞懂Go语言中的Context
微博、虎牙挺进兴趣社区:同行不同路
左右对齐!
科普达人丨一文看懂阿里云的秘密武器“神龙架构”
C1 certification learning notes 3 -- Web Foundation
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
js平铺数据查找叶子节点
函数式接口,方法引用,Lambda实现的List集合排序小工具