Object.FindObjectsOfType 查找Type物体

static function FindObjectsOfType (type : Type) : Object[]

Description描述

Returns a list of all active loaded objects of Type type.

返回Type类型的所有激活的加载的物体列表

It will return no assets (meshes, textures, prefabs, ...) or inactive objects.

它将返回任何资源(网格,纹理,预设,...)或激活的物体。

Please note that this function is very slow. It is not recommended to use this function every frame. In most cases you can use the singleton pattern instead.

请注意这个函数是非常慢的。不推荐在每帧使用这个函数,大多数情况下你可以使用单例模式代替。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnMouseDown() {
		HingeJoint[] hinges = FindObjectsOfType(typeof(HingeJoint)) as HingeJoint[];
		foreach (HingeJoint hinge in hinges) {
			hinge.useSpring = false;
		}
	}
}
// When clicking on the object, it will disable all springs on all hinges in the scene.
//当点击物体,它将禁用场景中所有铰链中的弹簧
function OnMouseDown () {
	var hinges : HingeJoint[] = FindObjectsOfType(HingeJoint) as HingeJoint[];
	for (var hinge : HingeJoint in hinges) {
		hinge.useSpring = false;
	}
}
最后修改:2010年12月8日 Wednesday 23:51

本脚本参考基于Unity 3.4.1f5

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