BITFALL/Assets/Artists/Scripts/Entities/GameMode/EntitySpawnPoint.cs

47 lines
944 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using BITFALL.Scene;
using BITKit;
using BITKit.Entities;
using Cysharp.Threading.Tasks;
using UnityEngine;
namespace BITFALL.Entities.GameMode
{
public class EntitySpawnPoint : EntityBehavior
{
[SerializeReference, SubclassSelector, Inject]
private ISpawnPointService _spawnPointService;
[Inject] private IEntityMovement _movement;
public override async void OnStart()
{
base.OnStart();
try
{
await UniTask.NextFrame(destroyCancellationToken);
}
catch (OperationCanceledException)
{
return;
}
if (Data.Get<int>(BITConstant.Environment.mp_respawn_on_death) is 0) return;
try
{
Matrix4x4 spawnPoint = _spawnPointService.RequestSpawnPoint();
_movement.Position = spawnPoint.GetPosition();
_movement.Rotation = spawnPoint.rotation;
}
catch (ArgumentOutOfRangeException)
{
}
}
}
}