【发布时间】:2017-08-02 01:21:45
【问题描述】:
我试图通过 youtube 上的 gamesplusjames 学习如何做到这一点,但效果不太好。我很确定这是小事,但我无法弄清楚它是什么。基本上,当我释放 C 键时,我的角色瞄准她的弓箭并射击。但我需要延迟,这样她的射击速度就不会超过她的动画移动速度。谁能告诉我我在哪里丢球?我简化了我的代码,以摆脱与射击或瞄准无关的所有其他垃圾。谢谢。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class tulMove : MonoBehaviour {
public Transform arrowSpawn;
public GameObject arrowPrefab;
private bool aim = false;
private bool shot = false;
public float shotDelay;
private float shotDelayCounter;
private Rigidbody2D rb;
private Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
rb = GetComponent<Rigidbody2D>();
}
void Update(){
if (!aim && Input.GetKeyDown (KeyCode.C))
{
aim = true;
anim.SetTrigger ("aim");
}
if (aim && !shot && Input.GetKeyUp (KeyCode.C))
{
shot = true;
aim = false;
anim.SetTrigger ("shot");
Instantiate (arrowPrefab, arrowSpawn.position, arrowSpawn.rotation);
shotDelayCounter = shotDelay;
}
if (aim && !shot && Input.GetKeyUp (KeyCode.C))
{
shotDelayCounter -= Time.deltaTime;
if (shotDelayCounter <= 0)
{
shotDelayCounter = shotDelay;
shot = true;
aim = false;
anim.SetTrigger ("shot");
Instantiate (arrowPrefab, arrowSpawn.position, arrowSpawn.rotation);
}
}
}
}
【问题讨论】:
-
您能否发布视频的链接,并描述当前出了什么问题?比如,您是在暗示动画当前过快吗?
-
嗯,视频不完全适合我的情况,但可以肯定。这就像 20 分钟,但他只是在前几分钟做计时器的事情,然后开始制造健康,这无关紧要。 youtube.com/watch?v=F6hUIU72JwE
-
对不起,如果我不清楚。我只是想让一个计时器基本上工作。现在我没有得到结果。我可以使用没有问题的浮动来调整下一个箭头出来所需的时间。首先让代码工作是个问题。
标签: c# timer delay wait unity2d