Hey,
I’ve made a small script.When i click on a Object,it should change his colour.When i click again it should change the color back.This should go on and on.My script works perfectly.I have only one Problem.The Update function restarts every frame.But one mouse click is longer then one frame.The result is taht the Object start flickering as long as you click.I hope you can help me ![]()
var fake = 1;
function Update ()
{
if (Input.touchCount > 0)
{
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(0).position);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
if (hit.collider.tag == "cube" fake == 1){
red();
}
else {
green();
}
}
}
}
function red() {
fake++;
renderer.material.color = Color.red;
yield WaitForSeconds(0.5);
}
function green() {
fake--;
renderer.material.color = Color.green;
yield WaitForSeconds(0.5);
}