2022-10-23 15:49:05 -04:00

38 lines
939 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vanisher : MonoBehaviour
{
[SerializeField]
private float timeToVanish;
[SerializeField]
private float timeToAppear;
private GrappleHook grapple;
private bool isVanishing = false;
//TODO represent obj is breaking
public void Begin(GrappleHook grapple){
if(isVanishing)return;
this.grapple = grapple;
Invoke("Vanish", timeToVanish);
isVanishing = true;
}
private void Vanish(){
grapple.Unhook();
gameObject.SetActive(false);
Invoke("Appear", timeToAppear);
isVanishing = false;
}
private void Appear(){
gameObject.SetActive(true);
}
private void OnCollisionEnter(Collision other) {
if(other.gameObject.tag.Equals("Player")){
Begin(other.gameObject.GetComponent<GrappleHook>());
}
}
}