Network.Destroy 销毁

static function Destroy (viewID : NetworkViewID) : void

Description描述

Destroy the object associated with this view ID across the network.

跨网络销毁与该viewID相关的物体。

The object is destroyed locally and remotely.

本地的和远端的都会被销毁。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float timer = 0;
	void Awake() {
		timer = Time.time;
	}
	void Update() {
		if (Time.time - timer > 2)
			Network.Destroy(GetComponent<NetworkView>().viewID);

	}
}
var timer : float = 0;
function Awake () {
	timer = Time.time;
}
// Network destroy the object which has this script
// it must have a NetworkView attached
//通过网络销毁拥有该脚本的物体,必须具备NetworkView属性
function Update() {
	if (Time.time - timer > 2) {
		Network.Destroy(GetComponent(NetworkView).viewID);
	}
}

• static function Destroy (gameObject : GameObject) : void

Description描述

Destroy the object across the network.

跨网络销毁该物体。

The object is destroyed locally and remotely.

本地的和远端的都会被销毁。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public float timer = 0;
	void Awake() {
		timer = Time.time;
	}
	void Update() {
		if (Time.time - timer > 2)
			Network.Destroy(gameObject);

	}
}
var timer : float = 0;
function Awake () {
	timer = Time.time;
}
// Network destroy the object which has this script
//网络销毁具有该脚本的物体
function Update() {
	if (Time.time - timer > 2) {
		Network.Destroy(gameObject);
	}
}
最后修改:2011年4月4日 Monday 16:09

本脚本参考基于Unity 3.4.1f5

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