Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/DinoCameraFollow.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoCameraFollow.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/DinoCameraFollow.cs
-
curl -L -o DinoCameraFollow.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/DinoCameraFollow.cs
1.04 kB
| using UnityEngine; | |
| public class DinoCameraFollow : MonoBehaviour | |
| { | |
| public Vector3 offset = new Vector3(0f, 6f, -9f); | |
| public float followSpeed = 6f; | |
| public bool followX = false; | |
| DinoPlayer target; | |
| void LateUpdate() | |
| { | |
| if (target == null) | |
| target = FindLocalPlayer(); | |
| if (target == null) | |
| return; | |
| Vector3 desired = target.transform.position + offset; | |
| if (!followX) | |
| desired.x = 0f; | |
| transform.position = Vector3.Lerp(transform.position, desired, Time.deltaTime * followSpeed); | |
| transform.rotation = Quaternion.Lerp( | |
| transform.rotation, | |
| Quaternion.Euler(20f, 0f, 0f), | |
| Time.deltaTime * followSpeed | |
| ); | |
| } | |
| DinoPlayer FindLocalPlayer() | |
| { | |
| DinoPlayer[] players = FindObjectsOfType<DinoPlayer>(); | |
| foreach (DinoPlayer p in players) | |
| { | |
| if (p.Object != null && p.Object.HasInputAuthority) | |
| return p; | |
| } | |
| return null; | |
| } | |
| } | |