From 20cbc182ac4446b2e603f64e2af16cfafefe7d96 Mon Sep 17 00:00:00 2001 From: Ciakon Date: Wed, 24 Apr 2024 07:27:55 +0200 Subject: [PATCH] Changed car controller script --- .../Timers/Racetrack mini_timers.json | 6 +- Assets/Scenes/Racetrack mini.unity | 103 ++++++------------ .../Scripts/Car Customization/Car Loader.cs | 2 +- Assets/Scripts/GameController.cs | 16 +-- Assets/Scripts/GameManager.cs | 6 +- ...{car control v2.cs => PlayerController.cs} | 2 +- ...ol v2.cs.meta => PlayerController.cs.meta} | 0 Assets/Scripts/gameController1.cs | 16 +-- 8 files changed, 59 insertions(+), 92 deletions(-) rename Assets/Scripts/{car control v2.cs => PlayerController.cs} (98%) rename Assets/Scripts/{car control v2.cs.meta => PlayerController.cs.meta} (100%) diff --git a/Assets/ML-Agents/Timers/Racetrack mini_timers.json b/Assets/ML-Agents/Timers/Racetrack mini_timers.json index 7f38358..282f02f 100644 --- a/Assets/ML-Agents/Timers/Racetrack mini_timers.json +++ b/Assets/ML-Agents/Timers/Racetrack mini_timers.json @@ -1,5 +1 @@ -<<<<<<< HEAD -{"count":1,"self":126.9664256,"total":128.27774499999998,"children":{"InitializeActuators":{"count":3,"self":0.0005032,"total":0.0005032,"children":null},"InitializeSensors":{"count":3,"self":0.0010048,"total":0.0010048,"children":null},"AgentSendState":{"count":6142,"self":0.15357179999999998,"total":0.22399,"children":{"CollectObservations":{"count":3687,"self":0.0535024,"total":0.0535024,"children":null},"WriteActionMask":{"count":3687,"self":0.0015038999999999999,"total":0.0015038999999999999,"children":null},"RequestDecision":{"count":3687,"self":0.0154119,"total":0.0154119,"children":null}}},"DecideAction":{"count":6142,"self":0.78694939999999991,"total":0.7915905,"children":{"RayPerceptionSensor.Perceive":{"count":7374,"self":0.0046410999999999996,"total":0.0046410999999999996,"children":null}}},"AgentAct":{"count":6142,"self":0.2942363,"total":0.2942363,"children":null}},"gauges":{"BensonV6.1.CumulativeReward":{"count":10,"max":8.810824,"min":-1.38237309,"runningAverage":2.48100185,"value":5.73337841,"weightedAverage":3.243383}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713870314","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 249cbe37-b739-48da-be83-8703208ec644 -accessToken 8HP4BNN_d2rYa9gBqxxeXFjsh8NpNokVC4_Asgt7liQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713870442"}} -======= -{"count":1,"self":92.9120832,"total":96.5726732,"children":{"InitializeActuators":{"count":3,"self":0.0029931999999999997,"total":0.0029931999999999997,"children":null},"InitializeSensors":{"count":3,"self":0.0030275999999999996,"total":0.0030275999999999996,"children":null},"AgentSendState":{"count":4577,"self":0.29683329999999997,"total":0.4523232,"children":{"CollectObservations":{"count":2748,"self":0.1129471,"total":0.1129471,"children":null},"WriteActionMask":{"count":2748,"self":0.0072223,"total":0.0072223,"children":null},"RequestDecision":{"count":2748,"self":0.0353205,"total":0.0353205,"children":null}}},"DecideAction":{"count":4577,"self":2.5310645999999997,"total":2.5676405,"children":{"RayPerceptionSensor.Perceive":{"count":5496,"self":0.0365759,"total":0.0365759,"children":null}}},"AgentAct":{"count":4577,"self":0.63164939999999992,"total":0.63164939999999992,"children":null}},"gauges":{"BensonV6.1.CumulativeReward":{"count":9,"max":7.858923,"min":-1.55353785,"runningAverage":1.28349817,"value":-1.43162537,"weightedAverage":0.562824965}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713879512","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\Magnus\\Desktop\\Ny unityting\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-Magnus -hubSessionId 85628495-4bbf-4ebf-9a76-a3f42df70699 -accessToken EEPtwPFiPvta5ZqQMsucb3gRCkHIFV3-eB85wNbfCdI005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713879609"}} ->>>>>>> 784bfaff4d1e5d2fa2a37110d4a8ce407f40dc4f +{"count":1,"self":11.436417599999999,"total":11.5803967,"children":{"InitializeActuators":{"count":3,"self":0.0015189,"total":0.0015189,"children":null},"InitializeSensors":{"count":3,"self":0.0009987,"total":0.0009987,"children":null},"AgentSendState":{"count":346,"self":0.0115626,"total":0.023475799999999998,"children":{"CollectObservations":{"count":210,"self":0.0038948,"total":0.0038948,"children":null},"WriteActionMask":{"count":210,"self":0.0010044,"total":0.0010044,"children":null},"RequestDecision":{"count":210,"self":0.0070139999999999994,"total":0.0070139999999999994,"children":null}}},"DecideAction":{"count":346,"self":0.1094216,"total":0.1094216,"children":{"RayPerceptionSensor.Perceive":{"count":420,"self":0,"total":0,"children":null}}},"AgentAct":{"count":346,"self":0.0070523999999999995,"total":0.0070523999999999995,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1713936336","unity_version":"2022.3.11f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2022.3.11f1\\Editor\\Unity.exe -projectpath C:\\Users\\noahk\\Documents\\Unity projects\\Racesm -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-noahk -hubSessionId 985081e8-b814-4bc7-8736-608aea67ce7e -accessToken fMKSu_LeJtSMMwbIluJ0HvaiatLXHDxWic8X4MA6BEQ005f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Racetrack mini","end_time_seconds":"1713936347"}} \ No newline at end of file diff --git a/Assets/Scenes/Racetrack mini.unity b/Assets/Scenes/Racetrack mini.unity index 3a2dda4..2d303c9 100644 --- a/Assets/Scenes/Racetrack mini.unity +++ b/Assets/Scenes/Racetrack mini.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.32097125, g: 0.21131825, b: 0.40435025, a: 1} + m_IndirectSpecularColor: {r: 0.32107174, g: 0.21133253, b: 0.40438062, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -7211,8 +7211,10 @@ GameObject: m_Component: - component: {fileID: 556260504} - component: {fileID: 556260503} + - component: {fileID: 556260505} + - component: {fileID: 556260506} m_Layer: 0 - m_Name: Car Loader + m_Name: GameManager m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -7264,6 +7266,33 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &556260505 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 556260502} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4ad347dab55166f40a93601eb1733707, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &556260506 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 556260502} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b00fe924fac7ccc488443310caf9e5b9, type: 3} + m_Name: + m_EditorClassIdentifier: + NextCarKey: 110 + NextCarButton: {fileID: 0} + PlayerCar: {fileID: 350793952} --- !u!4 &559703698 stripped Transform: m_CorrespondingSourceObject: {fileID: 43625883235569613, guid: 8e14ccd68551a1a4e93b83808515b996, type: 3} @@ -13784,6 +13813,10 @@ PrefabInstance: propertyPath: m_IsActive value: 0 objectReference: {fileID: 0} + - target: {fileID: 6698349112800946072, guid: b341ab9d1c90ec94ca57298c7d0a4eeb, type: 3} + propertyPath: m_IsActive + value: 0 + objectReference: {fileID: 0} - target: {fileID: 6825457734151485959, guid: b341ab9d1c90ec94ca57298c7d0a4eeb, type: 3} propertyPath: isVisible value: 0 @@ -18992,71 +19025,6 @@ MonoBehaviour: animator: {fileID: 1480005367} npcPrefab: {fileID: 153506, guid: 5e488cfd825ce044395037d93a9d8eb6, type: 3} audio: {fileID: 0} ---- !u!1001 &1492327422 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - serializedVersion: 3 - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 281105538288573982, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: PlayerCar - value: - objectReference: {fileID: 350793952} - - target: {fileID: 2362900685038639990, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_Name - value: GameController - objectReference: {fileID: 0} - - target: {fileID: 2362900685038639990, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_IsActive - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalPosition.x - value: 31.220337 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalPosition.y - value: 14.231196 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalPosition.z - value: 14.108478 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 6970569131258301195, guid: 420cdad33b21c264392db22c65595f6d, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_RemovedGameObjects: [] - m_AddedGameObjects: [] - m_AddedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 420cdad33b21c264392db22c65595f6d, type: 3} --- !u!1 &1493536274 stripped GameObject: m_CorrespondingSourceObject: {fileID: 3636523566108256591, guid: 9f63749b266355c4c8f8f5a8529d34cb, type: 3} @@ -28063,5 +28031,4 @@ SceneRoots: - {fileID: 998358590} - {fileID: 323815922} - {fileID: 454865284} - - {fileID: 1492327422} - {fileID: 556260504} diff --git a/Assets/Scripts/Car Customization/Car Loader.cs b/Assets/Scripts/Car Customization/Car Loader.cs index 5a153c4..e5177bb 100644 --- a/Assets/Scripts/Car Customization/Car Loader.cs +++ b/Assets/Scripts/Car Customization/Car Loader.cs @@ -29,7 +29,7 @@ public class CarLoader : MonoBehaviour void replaceCar(GameObject car, string color) { - car.GetComponent().enabled = true; + car.GetComponent().enabled = true; car.GetComponent().enabled = false; cam.GetComponent().getCar(car); diff --git a/Assets/Scripts/GameController.cs b/Assets/Scripts/GameController.cs index a102574..24a1b0b 100644 --- a/Assets/Scripts/GameController.cs +++ b/Assets/Scripts/GameController.cs @@ -16,8 +16,8 @@ public class GameController :MonoBehaviour public static bool RaceIsStarted { get { return true; } } public static bool RaceIsEnded { get { return false; } } - carcontrolv2 m_PlayerCar; - List Cars = new List(); + PlayerController m_PlayerCar; + List Cars = new List(); int CurrentCarIndex = 0; protected virtual void Awake () @@ -26,17 +26,17 @@ public class GameController :MonoBehaviour Instance = this; //Find all cars in current game. - Cars.AddRange (GameObject.FindObjectsOfType ()); + Cars.AddRange (GameObject.FindObjectsOfType ()); Cars = Cars.OrderBy (c => c.name).ToList(); foreach (var car in Cars) { - var userControl = car.GetComponent(); + var userControl = car.GetComponent(); var audioListener = car.GetComponent(); if (userControl == null) { - userControl = car.gameObject.AddComponent (); + userControl = car.gameObject.AddComponent (); } if (audioListener == null) @@ -49,7 +49,7 @@ public class GameController :MonoBehaviour } m_PlayerCar = Cars[0]; - m_PlayerCar.GetComponent ().enabled = true; + m_PlayerCar.GetComponent ().enabled = true; m_PlayerCar.GetComponent ().enabled = true; if (NextCarButton) @@ -69,13 +69,13 @@ public class GameController :MonoBehaviour private void NextCar () { - m_PlayerCar.GetComponent ().enabled = false; + m_PlayerCar.GetComponent ().enabled = false; m_PlayerCar.GetComponent ().enabled = false; CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count); m_PlayerCar = Cars[CurrentCarIndex]; - m_PlayerCar.GetComponent ().enabled = true; + m_PlayerCar.GetComponent ().enabled = true; m_PlayerCar.GetComponent ().enabled = true; } diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 1c6702c..ca3faa2 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -4,7 +4,11 @@ using UnityEngine; public class GameManager : MonoBehaviour { - // Start is called before the first frame update + public int lapAmount; + public GameObject[] checkpoints; + public GameObject[] players; + + int currentLap = 1; void Start() { diff --git a/Assets/Scripts/car control v2.cs b/Assets/Scripts/PlayerController.cs similarity index 98% rename from Assets/Scripts/car control v2.cs rename to Assets/Scripts/PlayerController.cs index 90cecc4..3ffdb30 100644 --- a/Assets/Scripts/car control v2.cs +++ b/Assets/Scripts/PlayerController.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class carcontrolv2 : MonoBehaviour +public class PlayerController : MonoBehaviour { public float motorTorque = 2000; public float brakeTorque = 2000; diff --git a/Assets/Scripts/car control v2.cs.meta b/Assets/Scripts/PlayerController.cs.meta similarity index 100% rename from Assets/Scripts/car control v2.cs.meta rename to Assets/Scripts/PlayerController.cs.meta diff --git a/Assets/Scripts/gameController1.cs b/Assets/Scripts/gameController1.cs index a46c282..a83a762 100644 --- a/Assets/Scripts/gameController1.cs +++ b/Assets/Scripts/gameController1.cs @@ -12,8 +12,8 @@ public class gameController1 : MonoBehaviour public static bool RaceIsStarted { get { return true; } } public static bool RaceIsEnded { get { return false; } } - carcontrolv2 m_PlayerCar; - List Cars = new List(); + PlayerController m_PlayerCar; + List Cars = new List(); int CurrentCarIndex = 0; protected virtual void Awake () @@ -22,17 +22,17 @@ public class gameController1 : MonoBehaviour Instance = this; //Find all cars in current game. - Cars.AddRange (GameObject.FindObjectsOfType ()); + Cars.AddRange (GameObject.FindObjectsOfType ()); Cars = Cars.OrderBy(c => c.name).ToList(); foreach (var car in Cars) { - var userControl = car.GetComponent(); + var userControl = car.GetComponent(); var audioListener = car.GetComponent(); if (userControl == null) { - userControl = car.gameObject.AddComponent (); + userControl = car.gameObject.AddComponent (); } if (audioListener == null) @@ -45,7 +45,7 @@ public class gameController1 : MonoBehaviour } m_PlayerCar = Cars[0]; - m_PlayerCar.GetComponent ().enabled = true; + m_PlayerCar.GetComponent ().enabled = true; m_PlayerCar.GetComponent ().enabled = true; if (NextCarButton) @@ -65,13 +65,13 @@ public class gameController1 : MonoBehaviour private void NextCar () { - m_PlayerCar.GetComponent ().enabled = false; + m_PlayerCar.GetComponent ().enabled = false; m_PlayerCar.GetComponent ().enabled = false; CurrentCarIndex = LoopClamp (CurrentCarIndex + 1, 0, Cars.Count); m_PlayerCar = Cars[CurrentCarIndex]; - m_PlayerCar.GetComponent ().enabled = true; + m_PlayerCar.GetComponent ().enabled = true; m_PlayerCar.GetComponent ().enabled = true; }