Selection.transforms 变换列表

static var transforms : Transform[]

Description描述

Returns the top level selection, excluding prefabs.

返回顶层的选择物,不包括预设物。

This is the most common selection type when working with scene objects.

当工作与场景物体时,这是最常用的选择类型。

// C# example
// Select Objects and make them look to the main Camera by pressing 'l'
//选择物体并使它们指向主摄像机通过按"l"
using UnityEngine;
using UnityEditor;

public class LookAtMainCamera : ScriptableObject {
	[MenuItem ("Example/Selection looks at Main Camera _l")]
	static void Look() {
		Camera camera = Camera.main;

		if (camera) {
			foreach (Transform transform in Selection.transforms) {
				Undo.RegisterUndo(transform, transform.name + " Looks at Main Camera" );
				transform.LookAt(camera.transform);
			}
		}
	}
	//The menu item will be disabled if nothing, is selected.
	//菜单项目将会失去效用,如果没有事物被选择。
	[MenuItem ("Example/Selection looks at Main Camera _l", true)]
	static bool ValidateSelection () {
		return Selection.transforms.Length != 0;
	}
}
最后修改:2011年4月11日 Monday 10:54

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。