博客
关于我
unity UGUI 点击button获取button的名字
阅读量:323 次
发布时间:2019-03-04

本文共 397 字,大约阅读时间需要 1 分钟。

如何使用Unity的EventSystem实现物体点击事件处理

在Unity中,你可以通过EventSystem来在物体上检测点击事件。以下是实现这一功能的具体步骤:

  • 首先,在Unity编辑器中创建一个空物体,并将脚本挂在这个物体上。脚本内容如下:
  • public void OnClick(){// 获取当前选中的物体var button = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;

    // 打印选中的物体名称print(button.name);

    }

    1. 将脚本挂在所创建的物体上。

    2. 在Inspector中,设置脚本的执行事件类型为"Pointer Down"以响应物体的点击事件。

    3. 这样,当玩家点击挂有该脚本的物体时,函数会输出选中的物体的名称。整个过程简单易懂,适合用于基础的交互操作开发。

    转载地址:http://qusq.baihongyu.com/

    你可能感兴趣的文章
    org.apache.ibatis.exceptions.PersistenceException:
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest'
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    org.springframework.amqp.AmqpConnectException:java.net.ConnectException:Connection timed out:connect
    查看>>
    org.springframework.beans.factory.BeanDefinitionStoreException
    查看>>
    org.springframework.boot.context.properties.ConfigurationBeanFactoryMetadata
    查看>>
    org.springframework.boot:spring boot maven plugin丢失---SpringCloud Alibaba_若依微服务框架改造_--工作笔记012
    查看>>
    SQL-CLR 类型映射 (LINQ to SQL)
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>
    org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
    查看>>
    org/hibernate/validator/internal/engine
    查看>>