栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

Unity:碰撞检测方法

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Unity:碰撞检测方法

背景: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);
        }
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/897710.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号