Merge branch 'master' of git@ooftooft.net:Racesm.git

This commit is contained in:
magn9775
2024-04-26 10:21:07 +02:00
25 changed files with 1464 additions and 832 deletions

View File

@@ -73,9 +73,6 @@ public class GameController :MonoBehaviour
PlayerCar = cars[CurrentCarIndex];
cam.GetComponent<CameraControl>().getCar(PlayerCar);
print(PlayerCar.name);
}
public static int LoopClamp (int value, int minValue, int maxValue)

View File

@@ -1,13 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.SearchService;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameManager : MonoBehaviour
{
public int lapAmount;
public GameObject[] checkpoints;
public GameObject[] players;
[HideInInspector] public List<string> playersFinished;
[HideInInspector] public List<string> playerTimes;
int[] playerLaps;
void Start()
@@ -24,10 +28,15 @@ public class GameManager : MonoBehaviour
// Update is called once per frame
void Update()
{
print("playersfinished: " + playersFinished.Count());
for (int i = 0; i < players.Count(); i++)
{
GameObject player = players[i];
if (playersFinished.Contains(player.name) || playersFinished.Contains(player.name + " (player)"))
continue;
bool isAI = true;
if (player.GetComponent<PlayerController>().enabled)
isAI = false;
@@ -55,9 +64,27 @@ public class GameManager : MonoBehaviour
if (playerLaps[i] > lapAmount)
{
player.GetComponent<Rigidbody>().isKinematic = true;
}
if (isAI)
{
playersFinished.Add(player.name);
player.GetComponent<AgentController>().enabled = false;
}
else
playersFinished.Add(player.name + " (player)");
player.GetComponent<PlayerController>().enabled = false;
float time = Random.Range(15f, 40f);
playerTimes.Add(time.ToString());
}
}
// race finished
if (playersFinished.Count() == players.Count())
{
SceneManager.LoadScene("WinScreen");
}
}
}

View File

@@ -123,13 +123,13 @@ public class PlayerController : MonoBehaviour
}
private void Update() {
// Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
// float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
Transform currentCheckpoint = checkpoints[checkpointsCollected].transform;
float checkpintDistance = distanceToCheckpoint(currentCheckpoint);
// if (checkpintDistance < 0.1f)
// {
// checkpointsCollected += 1;
// }
if (checkpintDistance < 0.1f)
{
checkpointsCollected += 1;
}
}
private void OnCollisionEnter(Collision other) {

View File

@@ -3,23 +3,26 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.Mathematics;
using UnityEngine.UI;
using TMPro;
public class MapSelectorScript : MonoBehaviour
{
public GameObject[] Maps;
GameObject currentMap;
quaternion currentRotation;
public GameObject CameraRotator;
public int scene;
public string scene = "ForestRacetrack";
public TextMeshProUGUI TellMap;
void Start()
{
DisableAllMaps();
SelectMap(0);
DisableAllMaps();
ChangeToTrack2();
}
private void FixedUpdate()
{
CameraRotator.transform.eulerAngles += Vector3.up * 0.7f;
TellMap.text = "Selected map: \n" + scene;
}
void DisableAllMaps()
@@ -33,20 +36,18 @@ public class MapSelectorScript : MonoBehaviour
void SelectMap(int index)
{
DisableAllMaps();
currentMap = Maps[index];
currentMap.SetActive(true);
Maps[index].SetActive(true);
}
public void ChangeToTrack2()
{
scene = 2;
scene = "ForestRacetrack";
SelectMap(0);
}
public void ChangeToTrack3()
{
scene = 3;
scene = "CityRacetrack";
SelectMap(1);
}

View File

@@ -10,7 +10,6 @@ public class SkyboxLoader : MonoBehaviour
void Awake()
{
skyboxToLoad = GameObject.Find("SkyboxManager").GetComponent<TimeOfDay>().skyboxMaterial;
Debug.Log("Skybox: " + skyboxToLoad);
if (skyboxToLoad == "Day")
{
RenderSettings.skybox = skyboxDay;

View File

@@ -6,26 +6,46 @@ using TMPro;
public class TimeOfDay : MonoBehaviour
{
public string skyboxMaterial = "not selected";
public GameObject DayLight;
public GameObject NightLight;
public string skyboxMaterial = "Night";
public Material DaySkybox;
public Material NightSkybox;
public GameObject[] Lights;
public static TimeOfDay Instance;
public TextMeshProUGUI MainText;
public TextMeshProUGUI TellTime;
void DisableAllLights()
{
foreach (GameObject light in Lights)
{
light.SetActive(false);
}
}
public void ChangeToDayTime()
{
NightLight.SetActive(false);
RenderSettings.skybox = DaySkybox;
DayLight.SetActive(true);
skyboxMaterial = "Day";
}
public void ChangeToNightTime()
{
skyboxMaterial = "Night";
DayLight.SetActive(false);
RenderSettings.skybox = NightSkybox;
NightLight.SetActive(true);
skyboxMaterial = "Night"; ;
}
private void Awake()
{
Instance = this;
DontDestroyOnLoad(gameObject);
DisableAllLights();
ChangeToNightTime();
}
private void Update()
{
MainText.text = "Selected time of day: \n" + skyboxMaterial;
TellTime.text = "Selected time of day: \n" + skyboxMaterial;
}
}