Spaces:
Sleeping
Sleeping
Download project/Assets/Scripts/Game/MovingObstacle.cs from alfarouqwebserver/SWS-Smarta: direct link, hf CLI and curl.
- Browser
- Download file 1.59 kB
-
https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/MovingObstacle.cs
- Command line
-
hf download hf://spaces/alfarouqwebserver/SWS-Smarta/project/Assets/Scripts/Game/MovingObstacle.cs
-
curl -L -o MovingObstacle.cs https://huggingface.co/spaces/alfarouqwebserver/SWS-Smarta/resolve/main/project/Assets/Scripts/Game/MovingObstacle.cs
1.59 kB
| using Fusion; | |
| using UnityEngine; | |
| public class MovingObstacle : NetworkBehaviour | |
| { | |
| public enum MoveType { Horizontal, Vertical, Swing, Rotate } | |
| public MoveType moveType = MoveType.Horizontal; | |
| public float amplitude = 1.2f; | |
| public float speed = 1.5f; | |
| public Vector3 axis = Vector3.right; | |
| public float rotateAngle = 45f; | |
| Vector3 startPos; | |
| Quaternion startRot; | |
| double startTime; | |
| public override void Spawned() | |
| { | |
| startPos = transform.position; | |
| startRot = transform.rotation; | |
| if (Object.HasStateAuthority) | |
| startTime = Runner.SimulationTime; | |
| } | |
| public override void FixedUpdateNetwork() | |
| { | |
| if (!Object.HasStateAuthority) | |
| return; | |
| float t = (float)(Runner.SimulationTime - startTime); | |
| float s = Mathf.Sin(t * speed); | |
| if (moveType == MoveType.Horizontal) | |
| { | |
| Vector3 pos = startPos + new Vector3(s * amplitude, 0f, 0f); | |
| transform.position = pos; | |
| } | |
| else if (moveType == MoveType.Vertical) | |
| { | |
| Vector3 pos = startPos + new Vector3(0f, s * amplitude, 0f); | |
| transform.position = pos; | |
| } | |
| else if (moveType == MoveType.Swing) | |
| { | |
| float angle = s * rotateAngle; | |
| transform.rotation = startRot * Quaternion.AngleAxis(angle, axis.normalized); | |
| } | |
| else if (moveType == MoveType.Rotate) | |
| { | |
| transform.rotation = transform.rotation * Quaternion.AngleAxis(speed * Runner.DeltaTime * 360f, axis.normalized); | |
| } | |
| } | |
| } | |