【发布时间】:2018-10-09 22:51:05
【问题描述】:
大家好,我正在尝试构建一个应用程序并尝试在滚动条上做事。
我在 Unity 的 Animator Controller 中有 3 个不同的层,所有的权重都为 1。第一层有加载动画,第 2 层有滚动动画,需要在层的顶部播放1个动画。
为了在滚动上调用动画,我编写了一个程序,该程序在滚动的基础上调用动画,因此第 2 层“take001”上的动画在滚动上播放取决于发生了多少滚动。
现在我想获取第 2 层动画的当前时间。
找到下面的代码和我在 Unity 中创建的图层的屏幕截图:
[参考图片]:https://imgur.com/j4Up4OE
using UnityEngine;
using System.Collections;
public class MouseMovementScript : MonoBehaviour {
Animator anim;
AnimatorStateInfo stateInfo;
AnimatorClipInfo[] myAnimatorClip;
double speedBase = 1;
void Start () {
anim = GetComponent<Animator>();
stateInfo = anim.GetCurrentAnimatorStateInfo(1);
//Output the name of the starting clip
}
// Update is called once per frame
void Update () {
var d = Input.GetAxis("Mouse ScrollWheel");
if (d > 0f)
{
Time.timeScale = 1;
anim.SetFloat("Direction", 1.0f);
anim.Play("take001");
StartCoroutine(TestCoroutine(d));
anim.Play("BoxAnimation001");
}
else if (d < 0f)
{
Time.timeScale = 1;
anim.SetFloat("Direction", -1.0f);
}
// Cursor
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast (ray, out hit))
{
if (Input.GetMouseButtonDown(0)){
if(hit.transform.tag == "Popup_1")
{
Application.ExternalCall("OpenPopup", 0);
}
else if(hit.transform.tag == "Popup_2")
{
Application.ExternalCall("OpenPopup", 1);
}
else if(hit.transform.tag == "Popup_3")
{
Application.ExternalCall("OpenPopup", 2);
}
else if(hit.transform.tag == "Popup_4")
{
Application.ExternalCall("OpenPopup", 3);
}
}
}
}
IEnumerator TestCoroutine(float d){
yield return new WaitForSeconds(d);
Time.timeScale = 0; } }
【问题讨论】: