请大家帮助动画统一3D [英] Please guys help with animation in unity 3D

查看:73
本文介绍了请大家帮助动画统一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

推荐答案

您可以尝试在最后一次鼠标事件发生时添加私有字段。这样,如果上次调用后没有足够的时间,你可以阻止方法执行。

类似于:

You could try to add a private field holding when the last mouse event happened. This way, you can prevent method from executing if not enough time passed since last invocation.
Something like:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆