本文介绍了请大家帮助动画统一3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,问题是如果我点击鼠标左键一次就会播放攻击动画而我的角色会进行攻击但是如果我在鼠标左键上点击多次,那么角色就会冻结并停止移动但是有可能旋转它。这是我附加到我的角色的脚本。

So, the problem is if I click once on left mouse button there plays attack animation and my character performs an attack but if I click more than one time on left mouse button the character just freezes and stops moving but it is possible to rotate it. Here is the script I have attached to my character.

using UnityEngine;
using System.Collections;

public class PlayerShot : MonoBehaviour {
	public GameObject Player;


	void Start(){

	}

	void Update(){

            if (Input.GetMouseButtonDown(0))
            {
                Player.GetComponent<Animator>().SetTrigger("Attack");

            }

            else if (Input.GetMouseButtonUp(0))
            {
                Player.GetComponent<Animator>().SetTrigger("Idle");

            }
        }

	}





什么我试过了:



我试图更改代码但没有结果



What I have tried:

I have tried to change the code but no result

推荐答案

using UnityEngine;
using System.Collections;

public class PlayerShot : MonoBehaviour
{
   public GameObject Player;

   private const float WAIT = 0.1f; // 1/10th of a second

   private float lastClik = 0f;

   void Update() {

      if (Time.time - lastClick > WAIT) {

         lastClick = Time.time;

         if (Input.GetMouseButtonDown(0))
         {
            Player.GetComponent<Animator>().SetTrigger("Attack");
         }
         else if (Input.GetMouseButtonUp(0))
         {
            Player.GetComponent<Animator>().SetTrigger("Idle");
         }
      }
   }
}



亲切。


Kindly.


这篇关于请大家帮助动画统一3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 23:16