making changes to lighting. This is a backup just in case

This commit is contained in:
Ranno Samuel Adson
2024-12-27 14:11:36 +02:00
parent 50bf9bc51b
commit 5df9dacfb5
123 changed files with 4392 additions and 2266591 deletions

View File

@@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarDrivingRoutine : MonoBehaviour
{
public AudioSource _stopSound;
public AudioSource _tireSound;
public Waypoint _waypoint;
public float speed = 5f; // Movement speed
public float rotationSpeed = 5f; // Rotation speed
public float waypointProximityThreshold = 0.5f; // Distance to consider "close enough" to a waypoint
// Update is called once per frame
void Update()
{
if (_waypoint == null) return;
// Move towards the waypoint
Vector3 targetPosition = _waypoint.transform.position;
float step = speed * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, targetPosition, step);
// Rotate towards the desired rotation
float targetRotation = _waypoint.DesiredRotation;
Quaternion desiredRotation = Quaternion.Euler(0, targetRotation, 0);
transform.rotation = Quaternion.RotateTowards(transform.rotation, desiredRotation, rotationSpeed * Time.deltaTime);
// Check if close enough to the waypoint
if (Vector3.Distance(transform.position, targetPosition) <= waypointProximityThreshold &&
Quaternion.Angle(transform.rotation, desiredRotation) <= 1f)
{
// Proceed to the next waypoint
_waypoint = _waypoint.Next;
if (_waypoint == null)
{
// Optional: Play stop sound when no more waypoints
_stopSound?.Play();
}
else
{
// Optional: Play tire sound when moving to the next waypoint
_tireSound?.Play();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b22594476f1d2ec40af5cd2b99c82a66
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
using System.Collections;
using UnityEngine;
public class Carbehavior : MonoBehaviour
{
public AudioSource _carAlarm;
[Header("Spotlights")]
public Light spotlight1; // First spotlight
public Light spotlight2; // Second spotlight
private bool lightsAreOn = false;
[Header("Material Emission")]
public GameObject carObjectWithRenderer; // GameObject holding the Renderer
private Renderer carRenderer;
private Material carMaterial;
private Color originalEmissionColor;
[Header("Light Intensity Settings")]
public float maxLightIntensity = 800f;
public float minLightIntensity = 0f;
private Coroutine flashingRoutine;
void Start()
{
// Fetch the Renderer component from the provided GameObject
if (carObjectWithRenderer != null)
{
carRenderer = carObjectWithRenderer.GetComponent<Renderer>();
if (carRenderer != null && carRenderer.material.HasProperty("_EmissionColor"))
{
carMaterial = carRenderer.material;
originalEmissionColor = carMaterial.GetColor("_EmissionColor");
}
else
{
Debug.LogError("Car Renderer or Emission property not found on the GameObject!");
}
}
else
{
Debug.LogError("GameObject holding the Renderer is not assigned!");
}
// Ensure lights start at full intensity
SetLightIntensity(maxLightIntensity);
}
// Detect when another collider enters the trigger
private void OnTriggerEnter(Collider other)
{
if (!_carAlarm.isPlaying)
{
_carAlarm.Play();
Debug.Log("Sound Played: Collider entered trigger.");
// Start flashing lights and emission
flashingRoutine = StartCoroutine(FlashLightsAndEmission());
}
}
// Detect when another collider exits the trigger
private void OnTriggerExit(Collider other)
{
if (_carAlarm.isPlaying)
{
_carAlarm.Stop();
Debug.Log("Sound Stopped: Collider exited trigger.");
// Stop flashing lights and emission
if (flashingRoutine != null)
{
StopCoroutine(flashingRoutine);
flashingRoutine = null;
}
// Reset light intensity and material emission
SetLightIntensity(maxLightIntensity);
ResetEmission();
}
}
// Coroutine to flash lights and emission
IEnumerator FlashLightsAndEmission()
{
while (true)
{
// Toggle lights
lightsAreOn = !lightsAreOn;
float currentIntensity = lightsAreOn ? maxLightIntensity : minLightIntensity;
SetLightIntensity(currentIntensity);
// Toggle material emission
if (carMaterial != null && carMaterial.HasProperty("_EmissionColor"))
{
if (lightsAreOn)
{
carMaterial.SetColor("_EmissionColor", originalEmissionColor);
}
else
{
carMaterial.SetColor("_EmissionColor", Color.black);
}
}
yield return new WaitForSeconds(0.5f);
}
}
// Helper method to set light intensity for both spotlights
void SetLightIntensity(float intensity)
{
if (spotlight1 != null) spotlight1.intensity = intensity;
if (spotlight2 != null) spotlight2.intensity = intensity;
}
// Reset material emission to its original state
void ResetEmission()
{
if (carMaterial != null && carMaterial.HasProperty("_EmissionColor"))
{
carMaterial.SetColor("_EmissionColor", originalEmissionColor);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6c5c3fd9f657a074eac371b6145dd13d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Waypoint : MonoBehaviour
{
public float DesiredRotation = 0;
public Waypoint Next;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnDrawGizmos()
{
if (Next == null) return;
Gizmos.color = Color.green;
Gizmos.DrawLine(transform.position, Next.transform.position);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c5d646b7451c3734c8ef145e68fb0e2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: