Teachers open the door but You must enter by yourself.

Open Media Lab.オープンメディアラボ

interactable が選択された時に処理を実行

  1. 対象のGameObjectにXR Simple Interactableをアタッチ
  2. 対象のGameObjectに以下のScriptをアタッチ
  3. 
    using UnityEngine;
    using UnityEngine.XR.Interaction.Toolkit;
    using UnityEngine.XR.Interaction.Toolkit.Interactables;
    
    public class Cube : MonoBehaviour
    {
    	public XRSimpleInteractable interactable;
    	public Transform leftController;//Near-Far Interactorをアタッチ
    
    	void OnSelect(SelectEnterEventArgs args){
    		var s=transform.localScale;
    		if(args.interactorObject.transform==leftController){
    			transform.localScale=s*0.5f;
    		}else{
    			transform.localScale=s*2f;
    		}
    		Debug.Log("selected");
    	}
    
    	void OnEnable(){ interactable.selectEntered.AddListener(OnSelect); }
    	void OnDisable(){ interactable.selectEntered.RemoveListener(OnSelect); }
    }
    
    
  4. InspectorでScriptのinetactableのフォームに、XR Simple Interactableを設定
  5. InspectorでScriptのleftControllerのフォームに、LeftController/Near-Far Interactorを設定
This site is powered by
Powered by MathJax