关于“playerA 碰到 物体B,出现dialog对话框,离开后dialog消失”的运行机制:
1,A设置box collider 2d( 打上“player”tag)
2,B设置box collider 2d (钩上trigger)
3,在物体B挂上代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class welcome : MonoBehaviour
{
public GameObject enterlog;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
enterlog.SetActive(true);
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.tag == "Player")
{
enterlog.SetActive(false);
}
}
}
注意“Player"首字母大写!!!!
网友评论