您当前的位置: 首页 >  unity

每日出拳老爷子

暂无认证

  • 5浏览

    0关注

    135博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity:碰撞检测方法

每日出拳老爷子 发布时间:2021-12-23 12:20:26 ,浏览量:5

背景:Unity游戏中碰撞检测有多种实现方法,有一些个人推荐记录一下。 具体方法
  1. OnCollider系列,虽然很常用,但个人并不是很推荐,因为这种方法需要获得Component的Collider,并不算最方便。
  2. CaracterController相关方法,只有进没有Exit,在不需要考虑Exit判定的情况下是简便好用的,但在触发对话这样要有Enter和Exit两个方法的场景就不太好用。
  3. ontrigger系列:这个目前是个人最推荐的,判定比较方便,方法也比较丰富,一般用Enter和Exit就可以了。
  4. 比如下面这段简单的代码,就可以方便地实现触发和关闭对话
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class showconv : MonoBehaviour
{
    public GameObject conv;
    public GameObject other;
    // Start is called before the first frame update
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.name == other.name) {
            conv.SetActive(true);
        }
    }
    private void OnTriggerExit(Collider other)
    {
        if (other.gameObject.name == other.name)
        {
            conv.SetActive(false);
        }
    }
}
关注
打赏
1657016083
查看更多评论
立即登录/注册

微信扫码登录

0.9331s