0
我正在使用Unity3D,并且我编程了增强现实。如果我触摸屏幕,触摸的位置有一个对象,我会做一些事情。 其实我想“我怎么能知道感动哪个游戏对象我如何知道使用Unity3D触摸哪个游戏对象
我的代码是在这里
using UnityEngine;
using System.Collections;
public class Atak : MonoBehaviour {
private Animator anim;
private GameObject kamera;
// Use this for initialization
void Start() {
anim = GetComponent<Animator>();
kamera = GameObject.FindGameObjectWithTag ("Kamera");
}
// Update is called once per frame
void Update() {
RaycastHit dokunma;
if (Physics.Raycast(kamera.transform.position,Input.mousePosition,10)&&
dokunma.collider.gameObject.tag=="Oyuncu" && Input.GetMouseButtonDown(0)
){
anim.SetBool ("Bekle", false);
anim.SetBool ("Saldir", true);
} else{
anim.SetBool ("Bekle", true);
anim.SetBool ("Saldir", false);
}
}
}
编辑给我的错误:未指定的地方variable'dokunma” 我不明白的使用。
我发布的代码没有问题,我也看不到您当前的代码。请在我的答案中复制新的'Update'函数以解决您的问题。 – Programmer
谢谢你的回答,但我不使用主相机。我使用vuforia相机,我不能Camera.main.ScreenPointToRay。并请检查我的开始功能,我设置名称kamera。 –
如果是这种情况,则用'kamera.GetComponent().ScreenPointToRay(Input.mousePosition);'替换'Camera.main.ScreenPointToRay(Input.mousePosition) –
Programmer