Unity Animation.CrossFade Animation.Play
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class PlayerControll : MonoBehaviour
{
Transform playerTransform;
Animation playerAnimation;
Rigidbody playerRigidbody;
public float moveSpeed;
public float jumpAbility;
bool canJump; void Start()
{
playerTransform = GetComponent<Transform>();
playerAnimation = GetComponent<Animation>();
playerRigidbody = GetComponent<Rigidbody>();
Debug.Log(playerTransform.name);
} void Update()
{
Move_Control();
} void Move_Control()
{
if (Input.GetKey(KeyCode.W))
{
playerTransform.Translate(Vector3.forward * Time.deltaTime * moveSpeed, Space.Self);
playerAnimation.Play("runforward");
} if (Input.GetKeyUp(KeyCode.W))
{
playerAnimation.CrossFade("idle", 0.3f);
} if (Input.GetKey(KeyCode.S))
{
playerTransform.Translate(Vector3.back * Time.deltaTime * moveSpeed, Space.Self);
playerAnimation.Play("runbackwards");
}
if (Input.GetKeyUp(KeyCode.S))
{
playerAnimation.CrossFade("idle", 0.3f);
} if (Input.GetKey(KeyCode.A))
{
playerTransform.Translate(Vector3.left * Time.deltaTime * moveSpeed, Space.Self);
playerAnimation.Play("strafeleft");
} if (Input.GetKeyUp(KeyCode.A))
{
playerAnimation.CrossFade("idle", 0.3f);
} if (Input.GetKey(KeyCode.D))
{
playerTransform.Translate(Vector3.right * Time.deltaTime * moveSpeed, Space.Self);
playerAnimation.Play("straferight");
} if (Input.GetKeyUp(KeyCode.D))
{
playerAnimation.CrossFade("idle", 0.3f);
} if (Input.GetKey(KeyCode.Space))
{
if (canJump)
{
playerRigidbody.AddForce(Vector3.up * jumpAbility, ForceMode.Impulse);
playerAnimation.Play("jump");
canJump = false;
}
}
} private void OnCollisionStay(Collision collision)
{
if (collision.transform.tag == "Ground")
{
canJump = true;
//playerAnimation.Play("idle");
playerAnimation.CrossFade("idle",0.2f);
}
}
}
按88行那样写只摁WSAD中的一个按键人物正常移动,但是不正常执行动画,人物会漂移;按89行那样写只摁WSAD中的一个按键人物正常移动,并且正常执行动画。
但是同时摁下WD或WA或SD或SA,人物都会漂移。
Unity Animation.CrossFade Animation.Play的更多相关文章
- Unity 2D Skeletal Animation
本文记录在Unity中制作2D 骨骼动画的笔记 Unity版本:4.3 Uni2D 使用骨骼动画前,把Sprite Mesh 的Type 改为 Grid ,设置合适的骨骼数量和分配权重 1.选中创建好 ...
- Animation & Property Animation 使用
本篇主要讲Animation 和 Property Animation的使用,最后会讲QQ管家桌面火箭作为例子: 在Android中开发动效有两套框架可以使用,分别为 Animation 和 Prop ...
- Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)
1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...
- unity, Animation crossfade需要两动画在时间上确实有交叠
unity现在播动画都用Animator了,但公司的老项用的还是Animation,今天遇到一个bug,是两个动画的衔接处不连贯. 最后发现是由于A动画已经播完之后B动画才开始播,而且还用了cross ...
- Unity 动画系统 Animation 和 Animator的小实例
本文结合一个很简单的动画demo,分别采用2种方法,来对比Animation和Animator的使用方式: 方法1:单独使用Animation 方法2:Animation结合Animator 动画De ...
- Unity 动画系统 Animation和Animator 常用小功能
- Unity 动画系统 Animation和Animator等常用类
- Unity 动画系统 Animation 和 Animator 联系与区别
- [Angular] Two ways to create Angular Animation, using animation() or using state()
We have two blocks to show to difference ways to do animation in Angular: <button (click)="t ...
随机推荐
- CodeForces 566D Restructuring Company (并查集+链表)
题意:给定 3 种操作, 第一种 1 u v 把 u 和 v 合并 第二种 2 l r 把 l - r 这一段区间合并 第三种 3 u v 判断 u 和 v 是不是在同一集合中. 析:很容易知道是用并 ...
- javascript jquery插入元素后事件会被注销
js jquery插入元素后事件会被注销 document.body.innerHTML += <div id="dd">test</div> //这 ...
- TensorFlow创建变量
1 使用tf.Variable函数创建变量 tf.Variable(initial_value=None,trainable=True,collections=None,validate_shape= ...
- scikit-learn 机器学习库
一 介绍 scikit-learn是Python的一个开源机器学习模块,它建立在NumPy,SciPy和matplotlib模块之上.值得一提的是,scikit-learn最先是由David Cour ...
- 关于php缓存技术一些见解
参考的网站[很重要] ①.模拟高并发: https://blog.csdn.net/yxwb1253587469/article/details/50572927 https://blog.csdn. ...
- 如果Laravel 报错 file_put_contents(): failed to open stream
问题解决方法 执行命令 php artisan cache:clear 并赋予 /storage 文件夹读写权限: chmod -R 777 storage: 若在执行 php artisan cac ...
- Sublime3插件安装
首先声明一下,小编是做后台开发出身,但是总是想捣鼓一些小的网站出来,可能是完美心作祟,感觉前端这边不能差事,所以就自己上了,一开始是用eclipse来开发的,具体原因忘了,也不知道怎么就开始用Subl ...
- 资深专家深度剖析Kubernetes API Server第3章(共3章)
在本系列的前两部分中我们介绍了API Server的总体流程,以及API对象如何存储到etcd中.在本文中我们将探讨如何扩展API资源. 在一开始的时候,扩展API资源的唯一方法是扩展相关API源代码 ...
- AtCoder - 2581 树状数组
You are given an integer sequence of length N, a= {a1,a2,…,aN}, and an integer K. a has N(N+1)⁄2 non ...
- PHP 实现实现多线程
前言 前些天帮同事查一个问题,第一次接触到了 PHP 的多线程,原以为 PHP 普遍都是单线程模型,并不适合多线程领域,花些时间翻了几个多线程的项目源码之后,发现 PHP 的多线程也颇有可取之处,活用 ...