Skip to content

Commit

Permalink
feat: welder rotation on fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pyoneerC committed Sep 26, 2024
1 parent 0d4bf8b commit c0bd590
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Assets/Scenes/Reparation.unity
Original file line number Diff line number Diff line change
Expand Up @@ -17337,6 +17337,10 @@ PrefabInstance:
propertyPath: audioSource
value:
objectReference: {fileID: 1128651442}
- target: {fileID: 4614605577419265582, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
propertyPath: welderPrefab
value:
objectReference: {fileID: 1071434719}
- target: {fileID: 4614605577419265582, guid: 6bacecc4f3df9584198879c73a6b6c36, type: 3}
propertyPath: weldingSound
value:
Expand Down
28 changes: 27 additions & 1 deletion Assets/Scripts/FixLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class FixLogic : MonoBehaviour
public AudioClip weldingSound;
public GameObject welderParticles;
public Welder welder;
public GameObject welderPrefab;

// Minimap circles and particles
public GameObject circle0;
Expand Down Expand Up @@ -46,7 +47,7 @@ private void OnTriggerEnter(Collider other)
if (!other.CompareTag("Leak")) return;
_isOverlapping = true;
_currentLeak = other.gameObject;
Debug.Log("Overlapping with leak. Hold 'F' to fix.");
StartCoroutine(RotateWelder());
}

private void OnTriggerExit(Collider other)
Expand Down Expand Up @@ -87,6 +88,8 @@ private IEnumerator FixLeak()
yield return null;
}

StartCoroutine(RotateWelder());

if (!_isOverlapping || _currentLeak == null)
{
Debug.Log("No longer overlapping with leak. Fix aborted.");
Expand All @@ -106,6 +109,8 @@ private IEnumerator FixLeak()

_isOverlapping = false;
_isFixing = false;

StartCoroutine(RotateWelder());
}

private void HandleMinimapCirclesAndParticles()
Expand Down Expand Up @@ -169,4 +174,25 @@ private static void GameOver()
{
Debug.Log("Game Over! You fixed 7 leaks.");
}

private IEnumerator RotateWelder()
{
var originalRotation = welderPrefab.transform.rotation;
var targetRotation = originalRotation * Quaternion.Euler(10f, 10f, 0f);

const float rotateDuration = 0.5f;
for (float t = 0; t < rotateDuration; t += Time.deltaTime)
{
welderPrefab.transform.rotation = Quaternion.Lerp(originalRotation, targetRotation, t / rotateDuration);
yield return null;
}
welderPrefab.transform.rotation = targetRotation;

for (float t = 0; t < rotateDuration; t += Time.deltaTime)
{
welderPrefab.transform.rotation = Quaternion.Lerp(targetRotation, originalRotation, t / rotateDuration);
yield return null;
}
welderPrefab.transform.rotation = originalRotation;
}
}

0 comments on commit c0bd590

Please sign in to comment.