Unity3D关于多点移动

这是关于人物多点移动的方法,同理相机跟随.很早之前写过的一个东西 ,提取一些东西分享一下

private void Move(Transform[] target,ref int count,out bool iscount)

{

    iscount = false;

    var relativePos = target[count].position - transform.position;

    Quaternion newRotation = Quaternion.LookRotation(relativePos);

    transform.rotation = Quaternion.RotateTowards(transform.rotation, newRotation, 80 * Time.deltaTime);

    // transform.LookAt(targetpos[count]);

    transform.localPosition = Vector3.MoveTowards(transform.localPosition, target[count].position, speed * Time.deltaTime);

    if (Vector3.Distance(transform.position, target[count].position) <= 0.1f)

    {

        iscount = true;

    }

    if (iscount == true)

    {

        if (count >= target.Length - 1)

        {

            isMove = false;

        }

        count = count + 1;

        Debug.Log(count);

        iscount = false;

    }

}
发布了4 篇原创文章 · 获赞 1 · 访问量 1335

猜你喜欢

转载自blog.csdn.net/obf2018/article/details/88118992