gpt4 book ai didi

c# - Unity 3D VR (5.6),如何使用 GVR Pointer Physic Raycaster 检测物体?

转载 作者:行者123 更新时间:2023-11-30 17:33:48 25 4
gpt4 key购买 nike

我的 Vr 项目就像一个使用 3d 对象作为选择的测验,所以我已经制作了一个有效的点击事件并使用 GVR Pointer Physic Raycaster,但问题是我不知道如何使用 GVR Pointer Physic Raycaster 获取对象名称.

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

public class spawn : MonoBehaviour {

//
int buatrandom;
int jumlahrandom = 16 ;

int objek1 ;
int objek2 ;
int objek3 ;

int checkobjek;
int checkobjekawal;

string simpan1;
string simpan2;
string simpan3;

public GameObject target1;
public GameObject target2;
public GameObject target3;

public int [] simpannomorobject ;
public GameObject[] nomorasset;

public float speed =10f;
public float berat = 1.0f;

private gerak coba;
// Use this for initialization
void Start () {
simpannomorobject = new int[3];
for (int i = 0; i < 2; i++) {
buatrandom = Random.Range (0, jumlahrandom);
simpannomorobject [i] = buatrandom;
if (i > 0){
if (i < 3) {
buatobjek ();
}
}
}
}

void buatobjek (){
objek1 = simpannomorobject [0];
objek2 = simpannomorobject [1];
objek3 = simpannomorobject [2];

simpan1 = objek1.ToString();
simpan2 = objek2.ToString();
simpan3 = objek3.ToString();

target1 = Instantiate (nomorasset [objek1], new Vector3 (0, 0, 3.0f), Quaternion.identity);
target2 = Instantiate (nomorasset [objek2], new Vector3 (4.0f, 0, 0), Quaternion.Euler(0,90,0));
target3 = Instantiate (nomorasset [objek3], new Vector3 (-4.0f, 0, 0), Quaternion.Euler(0,-90,0));

target1.AddComponent<BoxCollider> ();
target2.AddComponent<BoxCollider> ();
target3.AddComponent<BoxCollider> ();


EventTrigger eventTrigger1 = target1.AddComponent<EventTrigger> ();
EventTrigger eventTrigger2 = target2.AddComponent<EventTrigger> ();
EventTrigger eventTrigger3 = target3.AddComponent<EventTrigger> ();

EventTrigger.Entry entry1 = new EventTrigger.Entry( );
EventTrigger.Entry entry2 = new EventTrigger.Entry( );
EventTrigger.Entry entry3 = new EventTrigger.Entry( );

entry1.eventID = EventTriggerType.PointerDown;
entry1.callback.AddListener( ( data ) => { OnPointerDownDelegate( (PointerEventData)data ); } );

entry2.eventID = EventTriggerType.PointerDown;
entry2.callback.AddListener( ( data ) => { OnPointerDownDelegate( (PointerEventData)data ); } );

entry3.eventID = EventTriggerType.PointerDown;
entry3.callback.AddListener( ( data ) => { OnPointerDownDelegate( (PointerEventData)data ); } );

eventTrigger1.triggers.Add (entry1);
eventTrigger2.triggers.Add (entry2);
eventTrigger3.triggers.Add (entry3);

target1.AddComponent<gerak> ();
target2.AddComponent<gerak> ();
target3.AddComponent<gerak> ();


}

// Update is called once per frame
void Update () {

target1.transform.Rotate(0,100* Time.deltaTime,0);
target2.transform.Rotate(0,100* Time.deltaTime,0);
target3.transform.Rotate(0,100* Time.deltaTime,0);
}

public void OnPointerDownDelegate( PointerEventData data )
{
print (data.enterEventCamera.gameObject.name);
}
}

最佳答案

您可以使用 pointerCurrentRaycast 获取 PhysicRaycaster 检测到的对象名称不是 enterEventCamera

public void OnPointerDownDelegate(PointerEventData data)
{
print(data.pointerCurrentRaycast.gameObject.name);
}

关于c# - Unity 3D VR (5.6),如何使用 GVR Pointer Physic Raycaster 检测物体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43337527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com