Subversion Repository Public Repository

Nextrek

Diff Revisions 167 vs 168 for /3DSpace/Assets/SpaceUnity/_Demo/Scrips/SU_Thruster.cs

Diff revisions: vs.
  @@ -67,28 +67,28 @@
67 67 _cacheTransform = transform;
68 68
69 69 // Ensure that parent object (e.g. spaceship) has a rigidbody component so it can apply force.
70 - if (transform.parent.rigidbody != null) {
71 - _cacheParentRigidbody = transform.parent.rigidbody;
70 + if (transform.parent.GetComponent<Rigidbody>() != null) {
71 + _cacheParentRigidbody = transform.parent.GetComponent<Rigidbody>();
72 72 } else {
73 73 Debug.LogError("Thruster has no parent with rigidbody that it can apply the force to.");
74 74 }
75 75
76 76 // Cache the light source to improve performance (also ensure that the light source in the prefab is intact.)
77 - _cacheLight = transform.GetComponent<Light>().light;
77 + _cacheLight = transform.GetComponent<Light>().GetComponent<Light>();
78 78 if (_cacheLight == null) {
79 79 Debug.LogError("Thruster prefab has lost its child light. Recreate the thruster using the original prefab.");
80 80 }
81 81 // Cache the particle system to improve performance (also ensure that the particle system in the rpefab is intact.)
82 - _cacheParticleSystem = particleSystem;
82 + _cacheParticleSystem = GetComponent<ParticleSystem>();
83 83 if (_cacheParticleSystem == null) {
84 84 Debug.LogError("Thruster has no particle system. Recreate the thruster using the original prefab.");
85 85 }
86 86
87 87 // Start the audio loop playing but mute it. This is to avoid play/stop clicks and clitches that Unity may produce.
88 - audio.loop = true;
89 - audio.volume = soundEffectVolume;
90 - audio.mute = true;
91 - audio.Play();
88 + GetComponent<AudioSource>().loop = true;
89 + GetComponent<AudioSource>().volume = soundEffectVolume;
90 + GetComponent<AudioSource>().mute = true;
91 + GetComponent<AudioSource>().Play();
92 92 }
93 93
94 94 void Update () {
  @@ -110,14 +110,14 @@
110 110 // If the thruster is active...
111 111 if (_isActive) {
112 112 // ...and if audio is muted...
113 - if (audio.mute) {
113 + if (GetComponent<AudioSource>().mute) {
114 114 // Unmute the audio
115 - audio.mute=false;
115 + GetComponent<AudioSource>().mute=false;
116 116 }
117 117 // If the audio volume is lower than the sound effect volume...
118 - if (audio.volume < soundEffectVolume) {
118 + if (GetComponent<AudioSource>().volume < soundEffectVolume) {
119 119 // ...fade in the sound (to avoid clicks if just played straight away)
120 - audio.volume += 5f * Time.deltaTime;
120 + GetComponent<AudioSource>().volume += 5f * Time.deltaTime;
121 121 }
122 122
123 123 // If the particle system is intact...
  @@ -127,12 +127,12 @@
127 127 }
128 128 } else {
129 129 // The thruster is not active
130 - if (audio.volume > 0.01f) {
130 + if (GetComponent<AudioSource>().volume > 0.01f) {
131 131 // ...fade out volume
132 - audio.volume -= 5f * Time.deltaTime;
132 + GetComponent<AudioSource>().volume -= 5f * Time.deltaTime;
133 133 } else {
134 134 // ...and mute it when it has faded out
135 - audio.mute = true;
135 + GetComponent<AudioSource>().mute = true;
136 136 }
137 137
138 138 // If the particle system is intact...