Hi, i’ve been trying to change the material of an object when i click but it isn’t changing… i’m starting to learn c# , can someone help me??
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interruptor : MonoBehaviour {
public Light Luz;
public Material Luzacesa;
public Material Luzapagada;
public GameObject Lampada;
void OnTriggerStay (Collider other) {
if (Input.GetKeyDown (KeyCode.Mouse0)) {
Luz.enabled = !Luz.enabled;
if (Lampada.GetComponent<Renderer> ().material = Luzacesa) {
Lampada.GetComponent<Renderer> ().material = Luzapagada;
}
else if(Lampada.GetComponent<Renderer> ().material = Luzapagada){
Lampada.GetComponent<Renderer> ().material = Luzacesa;
}
}
}
}