-
Notifications
You must be signed in to change notification settings - Fork 2
/
Wheel_Effects.cs
114 lines (93 loc) · 2.64 KB
/
Wheel_Effects.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Wheel_Effects : MonoBehaviour
{
//Variables
[Header("Tire Mark Trail Renderers")]
public TrailRenderer[] Tire_Marks; //The Trail renderer(s) for the tracks
[Header("Tire Mark Particle Systems")]
public bool Enable_Particle_System;
public ParticleSystem[] Skid_Particles; //The particle system(s) for the particles
[Header("Tire Audio (Basically The Sound When Drifting)")]
public bool Enable_Audio;
public AudioSource Drift_Audio; //This would be like a tire screech sound
[Header("Script References")]
public Car_Controller car_Controller;
private bool Tire_Marks_Flag;
private bool is_drifting;
public void Start(){
foreach(TrailRenderer T in Tire_Marks){
T.emitting = false;
}
if(Enable_Particle_System){
foreach(ParticleSystem P in Skid_Particles){
P.Stop();
}
}
}
//Update function to check the drifting every frame
void FixedUpdate(){
Check_Drift();
}
//Check if drifting or braking
public void Check_Drift(){
if(Input.GetKey(KeyCode.Space)){
StartEmitter();
}
else if (car_Controller.tempo != 0.5){
StartEmitter();
is_drifting = true;
}
else{
StopEmitter();
is_drifting = false;
}
}
//Start Renderring Trail
public void StartEmitter(){
if(Tire_Marks_Flag) return;
//Drift Trail
foreach (TrailRenderer T in Tire_Marks)
{
T.emitting = true;
}
//Drift Particles
if(Enable_Particle_System && is_drifting){
foreach (ParticleSystem P in Skid_Particles)
{
P.Play();
}
}
//Drift Sound
if(Enable_Audio && is_drifting){
if(!Drift_Audio.isPlaying){
//Play the sound
Drift_Audio.Play();
}
}
Tire_Marks_Flag = true;
}
//Stop Renderring Trail
public void StopEmitter(){
if(!Tire_Marks_Flag) return;
//Drift Trai
foreach (TrailRenderer T in Tire_Marks)
{
T.emitting = false;
}
//Drift Particles
if(Enable_Particle_System){
foreach (ParticleSystem P in Skid_Particles)
{
P.Stop();
}
}
//Drift Sound
if(Enable_Audio){
//Stop playing the sound
Drift_Audio.Stop();
}
Tire_Marks_Flag = false;
}
}