I set up a turret that shoots at the player and has a temperature meter that can change color when the player gets to close. How could I go about getting the temperature to change from green to a blinking red and yellow, when the player gets too close?
using System.Collections;
public class TurretTemperture : MonoBehaviour
{
public Transform Target;
private float distance;
private Quaternion rotation;
private float lookAtDistance = 10;
private float reactionTime = 2;
void Update ()
{
if(Target)
{
distance = Vector3.Distance(Target.position, transform.position);
if (distance < lookAtDistance)
{
lookAt();
}
if (distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
}
else
{
Target = null;
}
}
void lookAt ()
{
renderer.material.color = Color.red;
rotation = Quaternion.LookRotation(Target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * reactionTime);
}
}
↧