zoukankan      html  css  js  c++  java
  • 检测物体并互动

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

    public class Interact
    {
    private Interact() { }
    public static class InteractInstance
    {
    public static Interact instance = new Interact();
    }
    public static Interact GetInstance()
    {
    return InteractInstance.instance;
    }

    public delegate void funtion(); //委托的方法

    public static Collider2D[] _collider2D; //检测到的物体
    public void Interacting(GameObject target, float radius, string colliderMask)
    {
    _collider2D = Physics2D.OverlapCircleAll(target.transform.position, radius, LayerMask.GetMask(colliderMask));
    if (_collider2D.Length > 0)
    {
    }
    else
    {
    }
    }
    public void Interacting(GameObject target, float radius, string colliderMask, funtion funtion1)
    {
    _collider2D = Physics2D.OverlapCircleAll(target.transform.position, radius, LayerMask.GetMask(colliderMask));
    if (_collider2D.Length > 0)
    {
    funtion1();
    }
    else
    {
    }
    }
    public void Interacting(GameObject target, float radius, string colliderMask, funtion funtion1, funtion funtion2)
    {
    _collider2D = Physics2D.OverlapCircleAll(target.transform.position, radius, LayerMask.GetMask(colliderMask));
    if (_collider2D.Length > 0)
    {
    funtion1();
    }
    else
    {
    funtion2();
    }
    }

    }

  • 相关阅读:
    11111
    JavaScript基础
    CSS使用
    CSS 基本
    前端之HTML
    Python 迭代器和生成器
    Python day11
    Python 函数
    第十七篇:django基础(二)
    第十六篇:django基础
  • 原文地址:https://www.cnblogs.com/wei1349/p/14598980.html
Copyright © 2011-2022 走看看