var target : Transform;
var moveSpeed = 3;
var rotationSpeed = 3;
var range : float=10f;
var range2 : float=10f;
var stop : float=0;
var myTransform : Transform;
function Awake()
{
myTransform = transform;
}
function Start()
{
target = GameObject.FindWithTag(“Player”).transform;
}
function Update () {
GetComponent(NavMeshAgent).destination = target.position; <----- Problem/error
//rotate to look at the player
var distance = Vector3.Distance(myTransform.position, target.position);
if (distance<=range2 && distance>=range){
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
}
else if(distance<=range && distance>stop){
//move towards the player
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeedTime.deltaTime);
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
else if (distance<=stop) {
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeedTime.deltaTime);
}
}
This code works with unity 5.4 but not 5.5. Unsure why too.
Except you didn’t! OP’s using UnityScript, where your syntax won’t work - they’re using the us equivalent of GetComponent(typeof(NavMeshAgent)). Also it seems like OP’s not got any #using strict going on, so the duck typing takes care of calling .destination on GetComponent(Type)'s return value.
@o0neza0o , from 5.5 and forwards, NavMeshAgent lives in UnityEngine.AI instead of UnityEngine, so you’ll have to import that. It’s just this on top of your script:
import UnityEngine.AI;
… I believe, my UnityScript isn’t very good.
I’m not sure if it’s a bug that Unity fails to update UnityScript, or if this is just a bit of silent deprecation. For C# code, all instances of NavMeshAgent gets automatically replaced with UnityEngine.AI.NavMeshAgent on update.
It’s not the first time I’ve seen the auto updater fail on UnityScript. It wouldn’t surprise me if its another quiet internal decision towards deprecating UnityScript.
Its the using statement. In C# you should have using UnityEngine.AI; at the top of your script. In UnityScript the equivalent statement is import UnityEngine.AI;