- Home /
Adding renderers to script?
var Distance; var Target : Transform; var Lookatdistance = 25.0; var attacksrange = 15.0; var movespeed = 5.0; var damping = 6.0;
function Update () { Distance = Vector3.Distance(Target.position, transform.position);
if(Distance < Lookatdistance)
{
renderer.material.color = Color.gray;
Lookat();
}
if(Distance > Lookatdistance)
{
renderer.material.color = Color.yellow;
}
if(Distance < attacksrange)
{
renderer.material.color = Color.red;
attack ();
}
}
function Lookat() { var rotation = Quaternion.LookRotation(Target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
function attack () { transform.Translate(Vector3.forward movespeed Time.deltaTime); }
private function applyColor(Green : Color) { var renderers: Component[] = GetComponentsInChildren(Renderer); for (var renderer: Renderer in renderers) renderer.material.color = Green; }
Im not sure if the script I used to add the renderer is wrong? it just doesnt seem to work, It's javascript can someone please help?
Your answer
![](https://koobas.hobune.stream/wayback/20220613114514im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Renderer material simple question 1 Answer
How to Render a Sliced Sprite to a Mesh? 0 Answers
Universal Render is stuck applying Cyan 1 Answer
Rendering 0 Answers
Can the Unity Renderer generate 30 bit color data? 0 Answers