Change material doesn't work on mobilephone
Hi everybody. I try to change the material color from the Player on button click. Its works fine on the Editor Playmode. If i run the game on my mobile phone nothing happens when i click on the button. Does anyone have any idea why this is so and if so how can I fix it?
I add the shader to "Always Included Shaders" but it dint help.(GraphicsSettings.html?_ga=2.80946071.1645375285.1604758287-165643784.1603302988)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class ShopChangeColor : MonoBehaviour
{
public Material myMaterials; public Material myMaterials2;
public void ChangeMaterialPlayerBodyToRed()
{
myMaterials.color = Color.red;
}
}
Answer by RicEnz · Nov 15, 2020 at 02:59 PM
Solved the problem. On the mobile version it change the material only in the scene. If i change the scene, it change the material to the old one.
Blockquote
This is my new Script.
Blockquote
public Material myMaterialsColor;
Blockquote
public static int ColorMaterial = 0;
Blockquote
public void ChangeMaterialEyeBallToOrange()
Blockquote
{
ColorMaterial = 0;
PlayerPrefs.SetInt("ColorMaterial", ColorMaterial);
PlayerPrefs.Save();
}
public void ChangeMaterialEyeBallToGreen()
Blockquote
{
ColorMaterial = 1;
PlayerPrefs.SetInt("ColorMaterial", ColorMaterial);
PlayerPrefs.Save();
}
Void update() {
Blockquote
if(ColorMaterial == 0)
{
myMaterialsColor.color = new Color32(255, 187, 0, 255);
}
if (ColorMaterial==1)
{
myMaterialsColor.color = Color.green;
}
PlayerPrefs.GetInt("ColorMaterial", ColorMaterial);
PlayerPrefs.Save();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613015447im_/https://answers.unity.com/themes/thub/images/avi.jpg)