- Home /
How can I control a bool flag or two the colors change and the rotation on/off ?
The code is working when I'm running the game the objectsToRotate are rotating and the material is changing colors make it looks like blinking.
but now I want to be able to control with a bool flag or two the lights on/off and the rotation on/off the same time while the game is running in runtime. and before running the game if setting it to true or false. also to be able to control it from other scripts.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChangeColors : MonoBehaviour
{
public List<Transform> objectsToRotate = new List<Transform>();
public float rotationSpeed;
public Material material;
public Vector3 targetAngle = new Vector3(-90f, 0f, 0f);
// 0,31,191
// 255,0,0
// Start is called before the first frame update
void Start()
{
StartCoroutine(SetTrue());
}
// Update is called once per frame
void Update()
{
if (rotationSpeed == 0)
{
for (int i = 0; i < objectsToRotate.Count; i++)
{
Transform t = objectsToRotate[i].transform;
float newAngle = Mathf.LerpAngle(t.localEulerAngles.x, targetAngle.x, Time.deltaTime);
t.localEulerAngles = new Vector3(newAngle, 0, 0);
}
}
for(int i = 0; i < objectsToRotate.Count; i++)
{
objectsToRotate[i].Rotate(new Vector3(Time.deltaTime * rotationSpeed, 0, 0));
}
}
public void setHighlight(bool highlight)
{
if (highlight)
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(0, 31, 191));
}
else
{
material.EnableKeyword("_EMISSION");
material.globalIlluminationFlags = MaterialGlobalIlluminationFlags.RealtimeEmissive;
material.SetColor("_EmissionColor", new Color(255,0,0));
}
}
IEnumerator SetTrue()
{
setHighlight(true);
yield return new WaitForSeconds(0.5f);
StartCoroutine(SetFalse());
}
IEnumerator SetFalse()
{
setHighlight(false);
yield return new WaitForSeconds(0.5f);
StartCoroutine(SetTrue());
}
}
Can you rewrite your question into a more succinct and descriptive one please? It sounds like one where you don't even need to show code. Just think of the problem then ask it in a way other people will have all the information needed tor resolve it.
$$anonymous$$aybe you will find articulating it is all you needed to do to figure it out yourself.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Select a boolean from an array 1 Answer
How to determine if rotation is clockwise or anticlockwise 2 Answers