當前位置: 首頁>>代碼示例>>C#>>正文


C# NavMeshPath.GetCornersNonAlloc方法代碼示例

本文整理匯總了C#中UnityEngine.NavMeshPath.GetCornersNonAlloc方法的典型用法代碼示例。如果您正苦於以下問題:C# NavMeshPath.GetCornersNonAlloc方法的具體用法?C# NavMeshPath.GetCornersNonAlloc怎麽用?C# NavMeshPath.GetCornersNonAlloc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnityEngine.NavMeshPath的用法示例。


在下文中一共展示了NavMeshPath.GetCornersNonAlloc方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CalculateDestination

    public override void CalculateDestination(Transform playerDestination)
    {
        Flowchart flow = GameObject.FindGameObjectWithTag ("Player").GetComponent<capsule>().flow;
        if (b1 && flow.GetIntegerVariable ("Blops1") < 0) {
            destination = GameObject.Find ("Blop1").transform.position;
            b1 = false;
            timeBeforeUpdate = 500;
        }
        else if (b2 && flow.GetIntegerVariable ("Blops2") < 0) {
            destination = GameObject.Find ("Blop2").transform.position;
            b2 = false;
            timeBeforeUpdate = 500;
        }
        else if (b3 && flow.GetIntegerVariable ("Blop3") < 0) {
            destination = GameObject.Find ("Blop3").transform.position;
            b3 = false;
            timeBeforeUpdate = 500;
        }
        else{
            timeBeforeUpdate = 50;
            Vector3 PDest = iapos;
            if(playerDestination != null)
                PDest = playerDestination.position;
            destination = iapos;
            NavMeshPath path = new NavMeshPath ();
            Transform player = GameObject.FindGameObjectWithTag ("Player").transform;
            NavMesh.CalculatePath (player.position, PDest , NavMesh.AllAreas, path);
            Vector3[] corners = new Vector3[100];
            int nbCorners = path.GetCornersNonAlloc (corners);
            GameObject[] obstacleSwitchs = GameObject.FindGameObjectsWithTag ("ObstacleSwitch");
            float initialDist = 0.0f;
            for (int i = 1; i < nbCorners; i++) {
                Vector3 diff = corners [i] - corners [i - 1];
                initialDist += diff.magnitude;
            }
            Debug.Log (initialDist);
            float nextDist = 0.0f;
            foreach (GameObject go in obstacleSwitchs) {
                nextDist = 0.0f;
                GameObject obstacle = go.GetComponent<Obstacle> ().obstacle;
                obstacle.SetActive (!obstacle.activeSelf);
                NavMesh.CalculatePath (player.position, iapos, 1, path);
                Vector3[] corners2 = new Vector3[1000];
                nbCorners = path.GetCornersNonAlloc (corners2);
                for (int i = 1; i < nbCorners; i++) {
                    Vector3 diff = corners2 [i] - corners2 [i - 1];
                    nextDist += diff.magnitude;
                }
                obstacle.SetActive (!obstacle.activeSelf);
                if ((nextDist > initialDist && flow.GetIntegerVariable("SferBleus")<0) ||
                    (nextDist < initialDist && flow.GetIntegerVariable("SferBleus")>0)	){

                    destination = go.transform.position;
                    initialDist = nextDist;
                }

            }
            //Debug.Log (nbCorners);

        }
    }
開發者ID:rstruk,項目名稱:ProjetLaby,代碼行數:61,代碼來源:AllyComportement.cs


注:本文中的UnityEngine.NavMeshPath.GetCornersNonAlloc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。