Files
GameDevGameJamV2/Assets/Scripts/Checkpoint.cs
2022-05-23 19:06:14 +02:00

35 lines
874 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace OMGeeky
{
public class Checkpoint : MonoBehaviour
{
private Animator animator;
private static readonly int IsActive = Animator.StringToHash( "IsActive" );
private void OnEnable()
{
animator = GetComponent<Animator>();
}
public void SetInactive()
{
if(animator != null)
animator.SetBool( IsActive, false );
}
private void OnTriggerEnter2D( Collider2D other )
{
if ( other.TryGetComponent( out Character character ) )
{
character.root.spawnPosition.SetInactive();
character.root.spawnPosition = this;
animator.SetBool( IsActive, true );
}
}
}
}