Image Unity 3D-多个目标不工作
我正在用Unity 3D为Android制作一个应用程序,其中包括用手机摄像头检测一个图案,然后它会出现一个平面(就像一个按钮),如果你点击它,它就会启动一个视频 因此,我有4个不同的图像目标,有4种不同的图案,在每个图像目标内部,当检测到图案时,会出现一个平面。当您触摸平面时,它将执行以下脚本:Image Unity 3D-多个目标不工作,image,unity3d,target,Image,Unity3d,Target,我正在用Unity 3D为Android制作一个应用程序,其中包括用手机摄像头检测一个图案,然后它会出现一个平面(就像一个按钮),如果你点击它,它就会启动一个视频 因此,我有4个不同的图像目标,有4种不同的图案,在每个图像目标内部,当检测到图案时,会出现一个平面。当您触摸平面时,它将执行以下脚本: using UnityEngine; using System.Collections; using System.Collections.Generic; public class PlayVid
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayVideo1 : MonoBehaviour
{
public string moviePath = "video1.mp4";
void Update () {
// Code for OnMouseDown in the iPhone. Unquote to test.
for (int i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {
Debug.Log("Starting Movie: " + moviePath);
Handheld.PlayFullScreenMovie (moviePath, Color.black, FullScreenMovieControlMode.Full);
Debug.Log("All Done!");
}
}
}
}
使用UnityEngine;
使用系统集合;
使用System.Collections.Generic;
公共课播放视频1:单一行为
{
公共字符串moviePath=“video1.mp4”;
无效更新(){
//iPhone中OnMouseDown的代码。取消引用以进行测试。
对于(int i=0;i
每个平面都有不同的脚本和不同的电影路径,例如:
飞机1具有PlayVideo1.cs和电影路径“video1.mp4”。
飞机2具有PlayVideo2.cs和电影路径“video2.mp4”。
飞机3具有播放视频3.cs和电影路径“video3.mp4”。
飞机4具有播放视频4.cs和电影路径“video4.mp4”
然后,当我用相机检测到4种模式中的一种时,当我单击按钮时,它总是播放相同的视频(“video3.mp4”例如),即使我用相机对焦的模式是平面1或2的模式
我做错了什么
谢谢大家! 这是因为您的代码没有检查正在单击的平面。它目前所做的只是检测是否有任何触摸输入 将您的代码更改为下面的代码
//On MouseUpAsButton is a Monobehaviour event that is called on every collider
//where the interaction is like a button (i.e. click down and release on the same collider)
public void OnMouseUpAsButton () {
Handheld.PlayFullScreenMovie (moviePath, Color.black, FullScreenMovieControlMode.Full);
}
还请注意,如果您使用的是Unity 4.6及更高版本,则必须将事件系统组件连接到场景中的某个游戏对象,否则将不会调用OnMouseUpAsButton
最后,Monobehvaior还有很多其他有用的事件,包括OnMouseEnter,OnMouseDown,OnMouseExit,OnMouseUp等
另外,鼠标事件在移动设备上确实有效,因此您可以安全地使用它