using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerRaycasts : MonoBehaviour {
    public GameObject otherPlayer;
    public GameObject[] deathAnimationObjs;
    GameObject _controller;
	void Start(){
		_controller = GameObject.FindGameObjectWithTag("GameController");
	}
    private void OnTriggerEnter2D(Collider2D collision)
    {
        
        if (collision.gameObject.tag == "enemy") {
            DieObj(this.gameObject);
            DieObj(otherPlayer);
            LoseALife();
        }
    }
    public void RestartPhysics() {
        GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        GetComponent<PlayerMoviment>().canMove = true;
    }
    void DieObj(GameObject obj) {
        obj.GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        obj.GetComponent<PlayerMoviment>().canMove =false ;
        foreach (GameObject deathAni in deathAnimationObjs) {
            deathAni.SetActive(true);
        }

    }
	public void DieBoth(){
		
		DieObj(this.gameObject);
		DieObj(otherPlayer);
		LoseALife();
	}
    void LoseALife() {
		_controller.GetComponent<LifeManager>().LoseALife();
    }
}
