Question by
smoky_gamer · Mar 26, 2017 at 08:23 AM ·
unity 5updatestatic variablechange color
why my static timer variable print 0 everytime i call the getcolor function?!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//the script for changing the background Color
public class sceneFading : MonoBehaviour {
public bool fadeIn = true;
static float minimum = 0.3f;
static float maximum = 1f;
static float duration=50f;
static float startTime;
public static Color color;
static float timer;
// Use this for initialization
void Awake () {
// obj.color = new Color(1f, 1f, 1f, 1f);
color = new Color(1f, 1f, 1f, minimum);
startTime = Time.time;
}
// Update is called once per frame
void Update() {
timer = Time.time;
/*
if (fadeIn)
{
float t = (Time.time - startTime) / duration;
color = new Color(1f, 1f, 1f, Mathf.SmoothStep(minimum, maximum, t));
}
if (!fadeIn)
{
float t = (Time.time - startTime) / duration;
color = new Color(1f, 1f, 1f, Mathf.SmoothStep(maximum, minimum, t));
}*/
}
public static Color getcolor()
{
float t = (timer - startTime) / duration;
Debug.Log("timer" + timer +"starttime" + startTime+ "dur"+duration);
color = new Color(1f, 1f, 1f, Mathf.SmoothStep(minimum, maximum, t));
return color;
}
}
Comment