【发布时间】:2021-03-29 06:36:59
【问题描述】:
我正在做一个挖泥游戏。有 2 个泥游戏对象(精灵)需要以正确的顺序挖掘。我为每个对象分配一个脚本。禁用 mud2 boxcollider 以防止它们移动,直到泥 1 被拖动以触发 L box collider 。但是当我尝试播放时,即使mud1没有触发L box collider,mud2仍然可以拖动。我还取消了mud2的box collider。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pg7_mud1 : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 startPosition;
public BoxCollider mud2;
// Start is called before the first frame update
void Start()
{
mud2.enabled = false;
}
// Update is called once per frame
void Update()
{
}
void OnMouseDown()
{
startPosition = this.gameObject.transform.position;
screenPoint = Camera.main.WorldToScreenPoint (gameObject.transform.position);
}
void OnMouseDrag()
{
Debug.Log("can drag");
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint (curScreenPoint);
this.transform.position = new Vector3(curPosition.x, -5f, curPosition.z);
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.name =="left-area")
{
Debug.Log("touched edge");
mud2.enabled = true;
}
}
【问题讨论】:
标签: visual-studio unity3d augmented-reality