how to change material on an object in unity 5
SO I am making this simple game and instead of making a padlock I thought I could have the objects on my world map scene I want the object color to be different to show that it is "locked." Bellow is the script that is on the objects that will change color.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class LevelLoader : MonoBehaviour {
public int LeveltoLoad;
public Material lockedlevel;
private string loadPrompt;
private bool inRange;
private int completedLevel;
private bool canLoadLevel;
void Start()
{
completedLevel = PlayerPrefs.GetInt ("Level Completed");
canLoadLevel = LeveltoLoad <= completedLevel ? true : false;
if (!canLoadLevel)
{
Instantiate (lockedlevel);
{
gameObject.GetComponent<Renderer> (lockedlevel).material;
}
}
}
void OnTriggerStay(Collider other)
{
inRange = true;
if (canLoadLevel) {
loadPrompt = " (Space) to load level " + LeveltoLoad.ToString ();
}
else
{
loadPrompt = "level_" + LeveltoLoad.ToString () + "is locked";
}
}
void Update()
{
if (Input.GetButtonDown ("Action") && inRange)
{
SceneManager.LoadScene ("level_" + LeveltoLoad.ToString());
}
}
void OnTriggerExit()
{
inRange = false;
loadPrompt = "";
}
void OnGUI()
{
GUI.Label (new Rect(30, Screen.height * .9f, 200, 40),loadPrompt);
}
}
Any help to figure out what I am missing would be great! Thanks.
Your answer
Follow this Question
Related Questions
Why the object using Vector3.MoveTowards is not moving down ? 1 Answer
Displaying Properties from Revit in Unity VR 0 Answers
Call animation only once? 1 Answer
Setting and serializing an object state visible/invisible through a random variable? 0 Answers
My RigidbodyFPS (Unity Standard Assets) had a little shaking when collide with another 3d Object. 3 Answers