简体   繁体   中英

Unity AR How can i trigger a button in the scene?

I have this little AR-Unityapp for Android and i try to play a video with a button. But the button should not be on the screen ( canvas ) it should be in the scene ( understandable? ). So i made a 3d plane which simply starts the video with a pointer down event but it won´t work. I know that its possible to make this but i have no idea how some help would be helpful ( xP ).

在此处输入图片说明

use a world canvas:

Create a canvas and set its "render mode" to "world". In that canvas you can put your button, give it a 3D location as you would with your plane, but you can use normal UI functionalities, such as buttons, instead of implementing click detections your self.

If you want to trigger a Pointer Down event just follow the steps below


  1. Add Physics Raycaster to your Camera as shown below 物理学雷斯特
  2. Add EventSystem object in your scene
    Right click in Hirarchy Window -> UI -> Event System
  3. Attack Event Trigger component to the required plane
    Select Plane -> Add Component -> Event Trigger -> Add Event of Pointer Down 在此处输入图片说明
  4. Now Call the Required method via PointerDown Event (In My case Plane.OnSelected())

  1. Steps 1 to 2 as above
  2. Attach the below Script to that Plane as below

     using UnityEngine; using UnityEngine.EventSystems; public class Plane : MonoBehaviour,IPointerDownHandler { public void OnPointerDown(PointerEventData eventData) { Debug.Log("CALLED"); } } 

    This Method will be called on Pointer Down on the required plane. As Seen in the above code we are using IPointerDownHandler interface of UnityEngine.EventSystems

I am sure this will clear your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM