Y
Y
yraiv2020-05-07 12:31:16
Unity
yraiv, 2020-05-07 12:31:16

How to change the color of an object in Unity3d?

I tried to change the color in different ways, I could not take the image component in any way to change the color directly. I found several options, of which + - there was one that did not give errors, but still nothing happens. I need to change the color of the image depending on the level. What am I doing wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelClick : MonoBehaviour
{

    public int Lvl;
    public int LvlNext;
    public int N;
    public GameObject Player;
    public GameObject Krug;

    public void Start()
    {
      Lvl = CharController.LVL;
        
    }
    public void OnMouseDown()
    {

        Debug.Log("Нажатие на кнопку уровня");
        if (Lvl == LvlNext)
        {
            SceneManager.LoadScene(N);
        }
    }
    public void Update()
    {
        if (Lvl > LvlNext)
        {
            Krug.GetComponent<Renderer>().material.color = Color.white;
            Debug.Log("смена на белый цвет кружка");
        }
        if (Lvl < LvlNext)
        {
            Krug.GetComponent<Renderer>().material.color = Color.black;
            Debug.Log("смена на черный цвет кружка");
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question