Hello. I’m trying to create a floor that heats up by being in contact with certain objects. and it cools when coming in contact with others.
The thing is that I want to show visually by the color of the floor if it is cold or hot. Because when it reaches its maximum temperature the floor falls.
CODE:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EstadosPlataforma : MonoBehaviour {
//Controller controller;
public float grados;
Rigidbody rgb;
public bool Helada, Ardiendo;
public Color StartColor;
public Color EndColorBlue;
public Color EndColorRed;
public GameObject Heat;
public GameObject Frio;
// Use this for initialization
void Start () {
grados = 0; //---DEGREES--//
rgb = GetComponent<Rigidbody> ();
Helada = false; //--FROZEN FLOOR--//
Ardiendo = false; //--BURNING FLOOR--//
}
// Update is called once per frame
void Update () {
if (grados >= 100f) {
Ardiendo = true;
} else {
Ardiendo = false;
}
if (grados <= -100f) {
Helada = true;
transform.gameObject.tag = "PlataformaHelada";
Frio.GetComponent<AudioSource>().enabled = true;
} else {
Helada = false;
transform.gameObject.tag = "Plataforma";
}
if (Ardiendo) {
rgb.constraints = RigidbodyConstraints.None;
Heat.GetComponent<AudioSource>().enabled = true;
Destroy (gameObject, 2);
}
}
void OnCollisionStay (Collision c) {
if (c.transform.tag == "Hielo" && grados > -100f) {
grados -= 3.5f * Time.deltaTime;
}
if (c.transform.tag == "Fuego" && grados < 100f) {
grados += 3.5f * Time.deltaTime;
}
if (c.transform.tag == "Golem" && grados <= 100f) {
grados += 1.5f * Time.deltaTime;
} else {
grados += 0f * Time.deltaTime;
}
}
}