In my game at every tap the color of 3 different gameobject changes between vìblack and white. probably the script isn’t good cause it makes the game really slow may you help me?
public Material materialb;
public Material materialn;
public bool colorblack;
int[] mat;
public static ColorChanging current;
void Awake()
{
if (current == null)
current = this;
else
return;
}
// Start is called before the first frame update
void Start()
{
colorblack= true;
}
// Update is called once per frame
void Update()
{
if (!BallMovement.current.gameOver && /*!PauseMenu.current.pause &&*/ MovimentoPalla.current.partito)
CahangeColor();
}
void ChangeColor()
{
if (gameObject != null)
{
if ((Input.GetMouseButtonDown(0) || Input.touches.Any(x => x.phase == TouchPhase.Began)) && !colorblack)
{
GetComponent<Renderer>().material = materialn;
colorblack= true;
}
else if ((Input.GetMouseButtonDown(0) || Input.touches.Any(x => x.phase == TouchPhase.Began)) && colorblack)
{
GetComponent<Renderer>().material = materialb;
colorblack= false;
}
}
}
Thank you!