【发布时间】:2020-06-02 13:31:51
【问题描述】:
我写了一个脚本,比如在 C# 中将球体螺旋旋转到中心。但是,脚本甚至在检测到图像目标之前就开始了,当我将图像目标放在相机前面时,脚本已经执行了。
我读到需要为此修改 DefaultTrackableBehaviour 脚本。我看到了一些视频,这些视频展示了如何在检测到图像目标时启动音频,但是当检测到图像目标时如何启动脚本。
这是我只想在检测到图像目标时为球体执行的脚本。执行时,球体将螺旋到中心 (0,0,0)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class spiralanti : MonoBehaviour
{
float angles;
float radiuss;
float angleSpeed;
float rSpeed;
// Start is called before the first frame update
void Start()
{
angles = 0;
radiuss = 1f;
angleSpeed = 250f;
rSpeed = 0.05f;
angles = Mathf.Max(0, Mathf.PI);
radiuss = Mathf.Max(0, radiuss);
//float x = 0;
// float y = 0;
// float z = 0;
}
// Update is called once per frame
void Update()
{
angles += Time.deltaTime * angleSpeed;
radiuss -= Time.deltaTime * rSpeed;
if (radiuss <= 0)
{
float x = 0;
float y = 1;
float z = 0;
transform.localPosition = new Vector3(x, y, z);
}
else
{
float x = radiuss * Mathf.Cos(Mathf.Deg2Rad * angles);
float z = radiuss * Mathf.Sin(Mathf.Deg2Rad * angles);
float y = 1;
transform.localPosition = new Vector3(x, y, z);
}
}
}
请帮忙。
【问题讨论】: