0
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)
{
    lookAt();
}

if (Distance > lookAtDistance)
{
}

if (Distance < attackRange)
{
    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);
}

I am trying to make my object go towards the player but i cant put anything in the slot where it prompts you to put the object i want it to follow the problem i believe is at line 2 but i have tried so many things and i cant do anything to fix it i would like to note i have another piece of code simialr to this in a different script and it works just fine.

4
  • 1
    What do you mean by 'but i cant put anything in the slot where it prompts you to put the object'? Commented Mar 30, 2018 at 23:40
  • its kinda hard to explain it if u want copy and paste the script into an object then make another object and u will see but ill try to explain it anyway the second line is a variable and the goal is to make the object follow the player object and there is a box where you specify the player object Commented Mar 30, 2018 at 23:44
  • You mean in the Inspector? Commented Mar 31, 2018 at 4:19
  • Btw. don't use Javascript in Unity as it's going to be removed soon. forum.unity.com/threads/… Commented Mar 31, 2018 at 6:25

1 Answer 1

0

Replace var Target = transform; with var Target:Transform; on line 2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.