add ckg
plantilla base para movimiento básico
This commit is contained in:
105
Assets/Game Kit Controller/Scripts/Others/fadeObject.cs
Normal file
105
Assets/Game Kit Controller/Scripts/Others/fadeObject.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class fadeObject : MonoBehaviour
|
||||
{
|
||||
[Header ("Main Settings")]
|
||||
[Space]
|
||||
|
||||
public bool vanishEnabled = true;
|
||||
|
||||
public float vanishSpeed;
|
||||
public Renderer meshRenderer;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool vanishAtOnce;
|
||||
public float delayToVanishAtOnce;
|
||||
|
||||
[Space]
|
||||
|
||||
public bool sendObjectToPoolSystemToDisable;
|
||||
|
||||
|
||||
Color originalColor;
|
||||
|
||||
bool originalColorStored;
|
||||
|
||||
|
||||
public void activeVanish (float newSpeed)
|
||||
{
|
||||
if (!vanishEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (meshRenderer == null) {
|
||||
meshRenderer = GetComponentInChildren<Renderer> ();
|
||||
}
|
||||
|
||||
if (meshRenderer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (newSpeed > 0) {
|
||||
vanishSpeed = newSpeed;
|
||||
}
|
||||
|
||||
if (sendObjectToPoolSystemToDisable) {
|
||||
if (originalColorStored) {
|
||||
meshRenderer.material.color = originalColor;
|
||||
} else {
|
||||
originalColor = meshRenderer.material.color;
|
||||
|
||||
originalColorStored = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameObject.activeSelf) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gameObject.activeInHierarchy) {
|
||||
return;
|
||||
}
|
||||
|
||||
StartCoroutine (changeColorCoroutine ());
|
||||
}
|
||||
|
||||
IEnumerator changeColorCoroutine ()
|
||||
{
|
||||
if (vanishAtOnce) {
|
||||
|
||||
WaitForSeconds delay = new WaitForSeconds (delayToVanishAtOnce);
|
||||
|
||||
yield return delay;
|
||||
|
||||
if (!sendObjectToPoolSystemToDisable) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
} else {
|
||||
if (meshRenderer != null) {
|
||||
Color alpha = meshRenderer.material.color;
|
||||
|
||||
while (alpha.a > 0) {
|
||||
alpha.a -= Time.deltaTime * vanishSpeed;
|
||||
|
||||
meshRenderer.material.color = alpha;
|
||||
|
||||
if (alpha.a <= 0) {
|
||||
if (!sendObjectToPoolSystemToDisable) {
|
||||
Destroy (gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (sendObjectToPoolSystemToDisable) {
|
||||
GKC_PoolingSystem.Despawn (gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user