using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GravityAndFall : MonoBehaviour
{
private void Update()
{
}
public void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Player")
{
collision.gameObject.GetComponent<game>().enabled = false;
}
else if(collision.gameObject.tag == "Player")
{
collision.gameObject.GetComponent<game>().enabled = true;
}
}
}
This question is very unclear but I am going to take a stab at interpreting it.
I think the question is “How to use the OnTriggerEnter2D Unity Event to disable a object when it enters and re-enable it when it leaves.”
To do that you would have to implement the OnTriggerExit2D(Collider2d collier) method.
void OnTriggerEnter2D(Collider2D collision)
{
if(collision.gameObject.tag == "Player")
{
collision.gameObject.GetComponent<game>().enabled = false;
}
}
void OnTriggerExit2D(Collider2D collision)
{
if(collisoin.gameObject.tag == "Player")
{
collision.gameObject.GetComponent<game>().enabled = true;
}
}
I hope that answers your question. If not please clearify so we can understand better.