2017-10-08 47 views
0

我正在開發一款賽車遊戲,我正在使用相同的場景將其劃分爲不同的級別。所以我想讓我的AI控制的汽車忽略上一級的方法點。如何忽略統一3d中軌道的先前方式點?

我該怎麼做?

// Checks for the distance to next way point. If it is less than written value, then pass to next way point. 
if (nextWaypointPosition.magnitude < nextWaypointPassRadius) 
{ 
    currentWaypoint ++; 
    totalWaypointPassed ++; 

    // If all way points are passed, sets the current way point to first way point and increase lap. 
    if (currentWaypoint >= waypointsContainer.waypoints.Count) 
    { 
     currentWaypoint = 0; 
     lap ++; 
    } 
} 

回答

0

您可以標記與

可變DontDestroyOnLoad

,這意味着加載新場景中的變量值:

我的代碼的一些部分如下將會持續,因爲這是你需要的情況。

如果您有需要保存任何其他變量,並讓他們堅持,即使在比賽結束後關閉並重新打開(如以前的成績,等...),你也可以使用

PlayerPrefs.SetFloat (「FloatName」,floatvalue);

和比你可以通過(ESSENTIA ;;ý只是一個鍵(字符串) - 值(任何標準類型像整數,浮點,雙等訪問它。)對

PlayerPrefs。 GetFloat( 「FloatName」)

0

您可以爲不同級別 (如waypointContainer1,waypointContainer2等)創建不同的waypointContainers。
然後在你的AI汽車的腳本中的start()函數,你可以分配電流水平的waypointContainer到一個我的車的waypointContainer。類似這樣的:

void Start(){ 
    if(levelNo == 1) waypointContainer = waypointContainer1; 
    else if(levelNo == 2) waypointContainer = waypointContainer2; 
    //And so on 
}