您的位置:首页 > 其它

沿着路线寻路

2016-05-14 08:15 330 查看

沿着路线寻路



using UnityEngine;
using System.Collections;

public class InfoUI : MonoBehaviour {

public Transform player;//获取玩家

public Transform[] path;//获取要去地方的点

int count1 = 0;//计时

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

Vector3 movedir = path[count1].position - player.position;
//判断超过点数清零
if (movedir.magnitude<1)
{
count1++;
if (count1>=path.Length)
{
count1 = 0;
}
}
//方向
player.transform.rotation = Quaternion.Slerp(player.transform.rotation, Quaternion.LookRotation(movedir), Time.deltaTime * 5);
//速度
player.transform.Translate(movedir.normalized * 5 * Time.deltaTime, Space.World);

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: