【发布时间】:2016-10-13 20:59:53
【问题描述】:
我对 Unity 的使用非常流利,但是关于 Mechanim 和 Animations 我目前还不是很擅长,所以请不要给我太多的困难,哈哈。所以我的 GameManager 脚本中有这个布尔值:
public bool countDownDone = false;
一旦我的“3,2,1,GO!”,这个布尔值就会被设置为真。倒数计时器在我的游戏开始时结束。在该布尔值设置为 true 之后,我的游戏中的所有内容都开始了。示例:
using UnityEngine;
using System.Collections;
public class PlaneMover : MonoBehaviour {
private GameManagerScript GMS; // Reference to my GameManager Script
public float scrollSpeed;
public float tileSizeZAxis;
public float acceleration; //This has to be a negative number in the inspector. Since our plane is coming down.
private Vector3 startPosition;
void Start () {
GMS = GameObject.Find ("GameManager").GetComponent<GameManagerScript> (); //Finds the Script at the first frame
// Transform position of the quad
startPosition = transform.position;
}
void Update () {
if (GMS.countDownDone == true) //Everything starts once the countdown ends.
{
/* Every frame - time in the game times the assigned scroll speed
and never exceed the length of the tile that we assign */
float newPosition = Mathf.Repeat (Time.time * scrollSpeed, tileSizeZAxis);
// New position equal to the start position plus vector3forward times new position
transform.position = startPosition + Vector3.forward * newPosition; // was vector3.forward
scrollSpeed += Time.deltaTime * acceleration; // This makes the plane increase in speed over time with
// whatever our acceleration is set to.
}
}
}
我有这个爬行动画,它在游戏一开始就播放(甚至在计时器结束之前)并且永远循环播放。我的问题是,一旦布尔值设置为“true”,如何使爬行动画也开始?或者我只是将它应用到一个 CoRoutine 并让它在 3 秒后播放?我已经对是否参考 Animation 或 Animator 进行了广泛的研究,我也对此感到困惑。有什么建议吗?如果您需要有关我的问题的更多图片或详细信息,请告诉我。谢谢! :)
以下是新代码
using UnityEngine;
using System.Collections;
public class Crawling : MonoBehaviour {
Animator animator;
private GameManagerScript GMS;
void Start ()
{
animator = GetComponent<Animator> ();
GMS = GameObject.Find ("GameManager").GetComponent<GameManagerScript> ();
}
void Update ()
{
if (GMS.countDownDone == true)
{
animator.Play("Main Character Crawling", 1);
}
}
}
【问题讨论】:
标签: c# animation unity3d boolean unity5