【发布时间】:2017-09-03 18:16:08
【问题描述】:
在 Animator 中,我有一个 Aiming 状态,它可以转换到 Movement 状态,然后从 Movement 回到 Aiming。还有一个 Aiming 参数类型 bool。
当我单击鼠标右键时,它正在瞄准,但随后立即切换回不瞄准的移动状态。
在从运动到瞄准的过渡中,瞄准设置为假,从瞄准到运动瞄准设置为真。
还有脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Soldier : MonoBehaviour
{
private Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
}
void Update()
{
var inputVelx = Input.GetAxis("Horizontal");
var inputVely = Input.GetAxis("Vertical");
transform.Rotate(0, inputVelx, 0);
anim.SetFloat("VelX", inputVelx);
anim.SetFloat("VelY", inputVely);
if (Input.GetMouseButton(1))
{
anim.SetBool("Aiming", false);
}
else
{
anim.SetBool("Aiming", true);
}
}
}
我目前正在使用 GetMouseButton,只要我按住鼠标右键,它就会一直瞄准。
但我想使用 GetMouseButtonDown 并使其成为鼠标右键单击将使其保持瞄准,再次单击将使瞄准成为错误。
我尝试使用 GetMouseButtonDown,但它只是瞄准,然后立即返回 false。
【问题讨论】: