So I have been trying and trying to resolve this issue. Basically the integer value for the color is assigned to theUI script in one scene and It is defiantly assigned. Next scene the Material changer script says that the color value is 0. Help me.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TheUI : MonoBehaviour {
private int color;
public Button multiplayer;
public Text multiplayertext;
public Button exit;
public Text exittext;
public Text ColorText;
public Dropdown ColorBox;
public Text ColorBoxText;
public Image ColorBoxArrow;
public int ColorProperty
{
get
{
return color;
}
}
private void Awake()
{
DontDestroyOnLoad(transform.gameObject);
}
private void Start()
{
ColorText.enabled = false;
ColorBox.enabled = false;
ColorBoxText.enabled = false;
ColorBoxArrow.enabled = false;
}
public void ColorSelect()
{
multiplayer.enabled = false;
exit.enabled = false;
multiplayertext.enabled = false;
exittext.enabled = false;
ColorText.enabled = true;
ColorBox.enabled = true;
ColorBoxText.enabled = true;
ColorBoxArrow.enabled = true;
}
public void Color()
{
color = ColorBox.value;
Debug.Log("the color is" + color);
}
public void Exit()
{
Application.Quit();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MaterialChanger : MonoBehaviour {
public int color;
TheUI myUI = new TheUI();
void Update () {
color = myUI.ColorProperty;
Debug.Log(color);
if (color == 4)
{
gameObject.GetComponent().material.color = Color.blue;
}
if (color == 3)
{
gameObject.GetComponent().material.color = Color.red;
}
if (color == 2)
{
gameObject.GetComponent().material.color = Color.yellow;
}
if (color == 1)
{
gameObject.GetComponent().material.color = Color.green;
}
}
}
↧