当前位置:网站首页>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);
}
}
}
边栏推荐
猜你喜欢
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
Deep learning network regularization
MySQL组合索引(多列索引)使用与优化案例详解
03 storage system
MySQL learning notes - data type (numeric type)
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
在芯片高度集成的今天,绝大多数都是CMOS器件
Dialogue with ye Yanxiu, senior consultant of Longzhi and atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
智能客服赛道:网易七鱼、微洱科技打法迥异
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
随机推荐
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
在芯片高度集成的今天,绝大多数都是CMOS器件
2022年九大CIO趋势和优先事项
Understand the context in go language in an article
Helix swarm Chinese package is released, and perforce further improves the user experience in China
How to build a technical team that will bring down the company?
一篇文章学会GO语言中的变量
JS tile data lookup leaf node
go-zero微服务实战系列(九、极致优化秒杀性能)
C1 certification learning notes 3 -- Web Foundation
Redis 发布和订阅
Halcon knowledge: NCC_ Model template matching
干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
Enter the width!
AI做题水平已超过CS博士?
Logstash~Logstash配置(logstash.yml)详解
mysql 联合主键_Mysql 创建联合主键[通俗易懂]
Redis 解决事务冲突之乐观锁和悲观锁
In today's highly integrated chips, most of them are CMOS devices
The performance of major mainstream programming languages is PK, and the results are unexpected