Пример #1
0
    void Update()
    {
        time += Time.deltaTime;
        if (time > 0.5f)
        {
            //如果点击鼠标右键,获取路径
            if (Input.GetMouseButtonDown(0))
            {
                finalPath = new List <Node>();
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hitInfo;
                if (Physics.Raycast(ray, out hitInfo))
                {
                    if (hitInfo.transform.CompareTag("floor"))
                    {
                        finalPath = path.GetPathFromGrid(playerPos.position, hitInfo.point);
                        index     = finalPath.Count - 1;
                    }
                }
            }

            time = 0.0f;//计时器重置
        }



        //按照预定义路径行走
        WalkByPreDefinedPath(finalPath);
    }