SkinnedCloth.SetEnabledFading 启用淡入淡出

function SetEnabledFading (enabled : bool, interpolationTime : float = 0.5f) : void


Fade the cloth simulation in or out, and enabled or disable the SkinnedCloth.


This function lets you enable or disabe the SkinnedCloth component, by setting the enabled parameter. Unlike setting the Cloth.enabled property directly, this will delay the action, and smoothly interpolate the mesh between the normal skinned mesh and the cloth simulation over a time of interpolationTime seconds. This helps you to turn on and off clothing simulation on characters without letting users notice the transition. Turning on and off clothing simulation is useful for managing the performance of your game, as cloth simulation is rather expensive. Calling this function repeatedly with the same parameters has no additional effect.


using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public bool simulateCloth = true;
	void Awake() {
		if (transform.position - Camera.main.transform.position.sqrMagnitude > 20.0F * 20.0F)
			simulateCloth = false;

// Smoothly turn cloth simulation on or off depending on distance to camera.

var simulateCloth = true;
if ((transform.position -Camera.main.transform.position).sqrMagnitude > 20.0f * 20.0f)
	simulateCloth = false;
GetComponent(SkinnedCloth).SetEnabledFading (simulateCloth);
Page last updated: 2011-3-26