Hello there,
I spent past four hours trying to make this script work:
using UnityEngine;
using System.Collections;
public class subSceneSelected : MonoBehaviour {
// Use this for initialization
public float period = 2;
public Color color = Color.red;
private Color originalColor;
private bool subsceneSelected = false;
/* Blinking started */
void Start () {
subsceneSelected = false;
originalColor = gameObject.renderer.material.color;
StartCoroutine(CheckEnable());
}
public IEnumerator CheckEnable() {
while (true){
if (!subsceneSelected) {//if subscene is not selected, change color
yield return StartCoroutine(ChangeColor());
}
yield return 0;
}
}
public IEnumerator ChangeColor() {
Material[] stuff= gameObject.renderer.materials;
for (int i=0; i < gameObject.renderer.materials.Length; i++){
if (stuff[i].color == originalColor) {
stuff[i].color = color;
}else {
stuff[i].color = originalColor;
}
}
yield return new WaitForSeconds(period);
}
void Update(){
}
void onMouseDown () {
if (subsceneSelected == false)
subsceneSelected = true;
//It then does something
}
}
When attached to an object, object blinks, and when this object is being selected with the mouse,on Mouse Down function, it then stops blinking and it then does something. But it’s never called. I’ve attached this script to some objects that have another scripts with MouseDown functions and they are working fine, but this isn’t. I even tried to comment code with blinking and it0s not working…or I’m just getting tired of Unity. Nothing makes sense…Do you have suggestion?