如何借助 VR 按钮停止物理传送带上的物体?

问题描述 投票:0回答:0

我正在制作一个基本的 VR 模型。在这个模型中,对象在物理传送带中移动。

我的问题是在 VR 按钮的帮助下降低传送带的速度。 我想当我点击 VR 按钮然后速度变为零并且物体应该停止在传送带中然后再次单击 VR 按钮然后速度变为一并且物体开始在传送带中移动。

但它不起作用。我认为我的编码有问题。我正在尝试这样做:当我点击 VR 按钮时,物体应该停止在传送带中,当我再次点击 VR 按钮时,物体开始移动。

我附上了我的代码:

enter code here

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

public class Conveyor : MonoBehaviour
{
public GameObject belt;
 public Transform endpoint;
 public float speed;
 public GameObject button;
 public UnityEvent onPress;
 public UnityEvent onRelease;
 GameObject press3;
 bool isPressed;
 void Start()
{
}
void OnTriggerStay(Collider other)
{
other.transform.position = Vector3.MoveTowards(other.transform.position, endpoint.position,speed * Time.deltaTime); 
}
  
private void OnTriggerEnter(Collider other)
{
 if(isPressed != press3)
 {
  button.transform.localPosition = new Vector3(0,0.015f,0);
  press3 = button;
  speed = 1;
  onPress.Invoke();
  isPressed =true;       
  }
  }
  private void OnTriggerExit(Collider other)    
  {
  if(isPressed = press3)
  {
  button.transform.localPosition =new Vector3(0,0.02f,0);
  speed =0;
  onRelease.Invoke();
  isPressed =false;            
  }   
}     
} 
c# unity3d button virtual-reality
© www.soinside.com 2019 - 2024. All rights reserved.