Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/DinoCameraShake.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 900 Bytes
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoCameraShake.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/DinoCameraShake.cs
-
curl -L -o DinoCameraShake.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoCameraShake.cs
900 Bytes
| using UnityEngine; | |
| public class DinoCameraShake : MonoBehaviour | |
| { | |
| public float shakeDuration = 0.2f; | |
| public float shakeStrength = 0.2f; | |
| float remaining; | |
| float strength; | |
| Vector3 originalPos; | |
| void Awake() | |
| { | |
| originalPos = transform.localPosition; | |
| } | |
| void LateUpdate() | |
| { | |
| if (remaining <= 0f) | |
| return; | |
| remaining -= Time.deltaTime; | |
| Vector3 random = Random.insideUnitSphere * strength; | |
| transform.localPosition = originalPos + new Vector3(random.x, random.y, 0f); | |
| if (remaining <= 0f) | |
| { | |
| transform.localPosition = originalPos; | |
| } | |
| } | |
| public void Shake(float duration, float intensity) | |
| { | |
| remaining = duration > 0f ? duration : shakeDuration; | |
| strength = intensity > 0f ? intensity : shakeStrength; | |
| originalPos = transform.localPosition; | |
| } | |
| } | |