Question by
BacN · Sep 01, 2015 at 08:39 PM ·
javascriptenemynoobcodepage
Could I get some help updating this code to unity 5?
I am such a noob at coding and I was wondering how This code could be used in unity 5
var Distance;
var Target : Transform;
var lookAtDistance = 25.0;
var attackRange = 15.0;
var moveSpeed = 5.0;
var Damping = 6.0;
function Update ()
{
Distance = Vector3.Distance(Target.position, transform.position);
if (Distance < lookAtDistance);
{
GetComponent<renderer.material.color=Color.yellow;
lookAt();
}
if (Distance > lookAtDistance);
{
renderer.material.color = Color.green;
}
if (Distance < attackRange);
{
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);
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612002318im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make object fall when user enters space 1 Answer
Enemy Health Won't go Down 1 Answer
Help..... please..... how do I do this? 0 Answers
Idle , Move and Attack animations 0 Answers
Error : BCE0018 Enemy ai 0 Answers