Нужна помощь со скриптом (Решено)
Добавлено: 10 дек 2018, 12:13
Привет всем. Есть скрипт, висит на персонаже. Скрипт возвращает перса на чекпоинт, если тот падает ниже -12 по Y и затемняет экран. Я добавил на перса префаб "SpwnEff" - вспышка при появлении. Всё работает - но только 1 раз.)) А мне надо, чтоб "SpwnEff" срабатывал каждый раз, когда перс возвращается на чекпоинт. Т.е. после включения префаб остаётся включён. Как в "void Update" (или ещё где) отключать, через пару сек, этот префаб, что б он потом опять включился?
Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FallDetect2 : MonoBehaviour
{
public Texture2D fadeOutTexture;
public float fadeSpeed = 0.8f;
public GameObject SpwnEff;
private int drawDepht = 1000;
private float alpha = 1.0f;
private int fadeDir = -1;
void OnGUI()
{
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
GUI.depth = drawDepht;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
}
public float BeginFade(int direction)
{
fadeDir = direction;
return (fadeSpeed);
}
void Start()
{
GameVariables.checkpoint = new Vector3(3, 6, -14);
SpwnEff SetActive(false);
}
void Update()
{
if (transform.position.y < -12)
{
transform.position = GameVariables.checkpoint;
alpha = 10;
SpwnEff SetActive(true);
}
}
void OnLevelWasLoaded()
{
// alpha = 1;
BeginFade(-1);
}
}
using System.Collections.Generic;
using UnityEngine;
public class FallDetect2 : MonoBehaviour
{
public Texture2D fadeOutTexture;
public float fadeSpeed = 0.8f;
public GameObject SpwnEff;
private int drawDepht = 1000;
private float alpha = 1.0f;
private int fadeDir = -1;
void OnGUI()
{
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha);
GUI.depth = drawDepht;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
}
public float BeginFade(int direction)
{
fadeDir = direction;
return (fadeSpeed);
}
void Start()
{
GameVariables.checkpoint = new Vector3(3, 6, -14);
SpwnEff SetActive(false);
}
void Update()
{
if (transform.position.y < -12)
{
transform.position = GameVariables.checkpoint;
alpha = 10;
SpwnEff SetActive(true);
}
}
void OnLevelWasLoaded()
{
// alpha = 1;
BeginFade(-1);
}
}