Skip to content

Commit 5a4f2cc

Browse files
committed
lapcounter脚本适配,以及对单选手模式添加了开局ui倒计时和ai小车延迟出发
1 parent da0dc66 commit 5a4f2cc

File tree

27 files changed

+452
-86
lines changed

27 files changed

+452
-86
lines changed

team_project/Assets/GameSystem/LapCounter.cs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,26 @@ public class LapCounter : MonoBehaviour
4949

5050
void Start()
5151
{
52-
playerCar.SetActive(false); // 确保玩家车在开始时不激活
53-
aiCar.SetActive(false); // 确保 AI 警车在开始时不激活
54-
StartCoroutine(StartRace()); // 启动协程处理倒计时和激活逻辑
55-
aiCar.SetActive(true); // 确保 AI 警车在开始时不激活
52+
Rigidbody PlayercarRigidbody = playerCar.GetComponent<Rigidbody>();
53+
if (PlayercarRigidbody != null)
54+
{
55+
PlayercarRigidbody.isKinematic = true; // 禁用物理运动
56+
// 或者使用 constraints
57+
// carRigidbody.constraints = RigidbodyConstraints.FreezeAll;
58+
}if(aiCar != null)
59+
{
60+
AICarPathFollower aiCarPathFollower = aiCar.GetComponent<AICarPathFollower>();
61+
aiCarPathFollower.enabled = false; // 确保 AI 小车的路径跟随脚本启用
62+
Rigidbody AicarRigidbody = aiCar.GetComponent<Rigidbody>();
63+
if (AicarRigidbody != null)
64+
{
65+
AicarRigidbody.isKinematic = true; // 禁用物理运动
66+
// 或者使用 constraints
67+
// carRigidbody.constraints = RigidbodyConstraints.FreezeAll;
68+
}
69+
}
70+
StartCoroutine(StartRace(PlayercarRigidbody,aiCar)); // 启动协程处理倒计时和激活逻辑
71+
5672
UpdateLapDisplay();
5773
UpdateTimeDisplay();
5874
UpdateSpeedDisplay();
@@ -83,14 +99,27 @@ void Start()
8399
Debug.LogWarning("AI car is not assigned in LapCounter!");
84100
}
85101
}
86-
IEnumerator StartRace()
102+
IEnumerator StartRace(Rigidbody playerCar,GameObject aiCar)
87103
{
88104
countdownscript.StartCountdown(5); // 开始5秒倒计时
89105
yield return new WaitForSeconds(5.0f); // 等待倒计时结束
90-
playerCar.SetActive(true); // 激活玩家车
106+
playerCar.isKinematic = false; // 激活玩家小车的物理运动
91107
Debug.Log("玩家小车已激活!");
92108
yield return new WaitForSeconds(3.0f); // 再等待5秒
93-
aiCar.SetActive(true); // 激活 AI 小车
109+
if(aiCar != null)
110+
{
111+
AICarPathFollower aiCarPathFollower = aiCar.GetComponent<AICarPathFollower>();
112+
Rigidbody AicarRigidbody = aiCar.GetComponent<Rigidbody>();
113+
if (aiCarPathFollower != null)
114+
{
115+
aiCarPathFollower.enabled = true; // 确保 AI 小车的路径跟随脚本启用
116+
AicarRigidbody.isKinematic = false; // 激活 AI 小车的物理运动
117+
}
118+
else
119+
{
120+
Debug.LogWarning("AI car does not have AICarPathFollower component!");
121+
}
122+
}
94123
Debug.Log("AI 小车已激活!");
95124
}
96125
void Update()

team_project/Assets/Infinity Code.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)