rabidus-test/Assets/Amazing Assets/Curved World/Example Scenes/Files/Scripts/RunnerChunk.cs

43 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-10-02 19:12:35 +03:00
using UnityEngine;
namespace AmazingAssets.CurvedWorld.Example
{
public class RunnerChunk : MonoBehaviour
{
public ChunkSpawner spawner;
void Update()
{
transform.Translate(spawner.moveDirection * spawner.movingSpeed * Time.deltaTime);
}
void FixedUpdate()
{
switch (spawner.axis)
{
case ChunkSpawner.AXIS.XPositive:
if (transform.position.x > spawner.destoryZone)
spawner.DestroyChunk(this);
break;
case ChunkSpawner.AXIS.XNegative:
if (transform.position.x < -spawner.destoryZone)
spawner.DestroyChunk(this);
break;
case ChunkSpawner.AXIS.ZPositive:
if (transform.position.z > spawner.destoryZone)
spawner.DestroyChunk(this);
break;
case ChunkSpawner.AXIS.ZNegative:
if (transform.position.z < -spawner.destoryZone)
spawner.DestroyChunk(this);
break;
}
}
}
}