Unity3D学习笔记(十四):Animation旧动画






旧动画系统:需要用代码来驱动Animation
自动添加动画,红色按钮

能侦测同属一个物体身上的脚本方法

2、旧动画,进入Rig,修改Legacy

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationManager : MonoBehaviour {
public GameObject prefs;
private float curTime = ;
private float interval = 1.0f;
void Update () {
if (Time.time < )
{
curTime += Time.deltaTime;
if (curTime >= interval)
{
Instantiate<GameObject>(prefs).transform.position = Vector3.right * Mathf.FloorToInt(Time.time);
curTime = ;
}
}
}
}
用代码控制Animation动画片段
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AnimationChange : MonoBehaviour {
public Animation anim;
void Update () {
if (Input.GetKeyDown(KeyCode.Q))
{
anim.Play("AnimationChangeMove");
}
if (Input.GetKeyDown(KeyCode.E))
{
anim.Play("AnimationChangeScale");
}
if (Input.GetKeyDown(KeyCode.S))
{
anim.Stop();
}
}
void SayBig()
{
Debug.Log("变大了");
}
void SaySmall()
{
Debug.Log("变小了");
}
}
递归树
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tree : MonoBehaviour {
public float size;
public GameObject treeGo;
public void CreateSelf()
{
if (size < 0.05f) return;//给递归添加限值
for (int i = ; i < ; i++)
{
GameObject go = Instantiate<GameObject>(treeGo);
go.transform.position = transform.position + transform.up * * size;
go.transform.rotation = transform.rotation;
go.transform.rotation *= Quaternion.AngleAxis(Random.Range(, ), Vector3.up) * Quaternion.AngleAxis(Random.Range(-, ), Vector3.right);
go.GetComponent<Tree>().size = size * 0.5f;
go.transform.localScale = Vector3.one * size * 0.5f;
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerAnimation : MonoBehaviour {
public Animation anim;
// Use this for initialization
void Start () { } // Update is called once per frame
void Update () {
//如果每帧检测到播放的是当前动画,则不会重复播放动画第一帧,会让动画继续播下去
//anim.Play("Idle");
if (Input.GetKeyDown(KeyCode.Alpha1))
{
anim.Play("Move");
}
if (Input.GetKeyDown(KeyCode.Alpha2))
{
anim.Play("Idle");
}
if (Input.GetKeyDown(KeyCode.Alpha3))
{
anim.Play("Death");
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum PlaySta
{
Move,
Idle,
Death
}
public class PlayerControl : MonoBehaviour {
public Animation anim;
public PlaySta playSta;
// Use this for initialization
void Start () {
playSta = PlaySta.Move;
} // Update is called once per frame
void Update () {
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
moveDir.x = h;
moveDir.z = v;
cd += Time.deltaTime;
Action();
}
void Action()
{
switch (playSta)
{
case PlaySta.Move:
Move();
break;
case PlaySta.Idle:
Idle();
break;
case PlaySta.Death:
Death();
break;
}
}
Vector3 moveDir;
Vector3 lookPoint;
RaycastHit hit;
public float moveSpeed = ;
void Move()
{
anim.Play("Move");
transform.position += moveDir * moveSpeed * Time.deltaTime;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, , << ))
{
lookPoint = hit.point;
lookPoint.y = transform.position.y;
transform.LookAt(lookPoint);
}
if (moveDir.magnitude < 0.01f)
{
playSta = PlaySta.Idle;
}
}
void Idle()
{
anim.Play("Idle");
if (moveDir.magnitude >= 0.01f)
{
playSta = PlaySta.Move;
}
}
float cd;
public void Damage()
{
cd = ;
playSta = PlaySta.Death;
}
void Death()
{
anim.Play("Death");
}
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Monster")
{
if (cd > 0.5f)
{
Damage();
}
}
}
}
抛异常的用法:
try:包含异常的语句
try不能单独使用,要搭配catch和finally使用
catch:捕获异常,可以填参数
catch(Exception e){},(Exception是所有异常的基类)
finally:最后都会执行,作为替补收尾工作,
无论如何都会执行,即使前面有return
结果:输出“捕获到了异常”,而“”不会输出
Unity3D学习笔记(十四):Animation旧动画的更多相关文章
- python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例
python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...
- (C/C++学习笔记) 十四. 动态分配
十四. 动态分配 ● C语言实现动态数组 C语言实现动态数组,克服静态数组大小固定的缺陷 C语言中,数组长度必须在创建数组时指定,并且只能是一个常数,不能是变量.一旦定义了一个数组,系统将为它分配一个 ...
- 【转】angular学习笔记(十四)-$watch(1)
本篇主要介绍$watch的基本概念: $watch是所有控制器的$scope中内置的方法: $scope.$watch(watchObj,watchCallback,ifDeep) watchObj: ...
- angular学习笔记(十四)-$watch(1)
本篇主要介绍$watch的基本概念: $watch是所有控制器的$scope中内置的方法: $scope.$watch(watchObj,watchCallback,ifDeep) watchObj: ...
- SharpGL学习笔记(十四) 材质:十二个材质球
材质颜色 OpenGL用材料对光的红.绿.蓝三原色的反射率来近似定义材料的颜色.象光源一样,材料颜色也分成环境.漫反射和镜面反射成分,它们决定了材料对环境光.漫反射光和镜面反射光的反射程度.在进行光照 ...
- Unity3D学习笔记(四)Unity的网络基础(C#)
一 网络下载可以使用WWW类下载资源用法:以下载图片为例WWW date = new WWW("<url>");yield return date;texture = ...
- Unity3D学习笔记(四):物理系统碰撞和预制体
Rigidbody(刚体组件):加了此组件游戏物体就变成刚体了 ----Mass(质量,单位kg):重力G = 质量m * 重力加速度g(g=9.81 m/s^2) --------冲量守恒定理 动量 ...
- Java学习笔记十四:如何定义Java中的类以及使用对象的属性
如何定义Java中的类以及使用对象的属性 一:类的重要性: 所有Java程序都以类class为组织单元: 二:什么是类: 类是模子,确定对象将会拥有的特征(属性)和行为(方法): 三:类的组成: 属性 ...
- [转]Unity3D学习笔记(四)天空、光晕和迷雾
原文地址:http://bbs.9ria.com/thread-186942-1-1.html 作者:江湖风云 六年前第一次接触<魔兽世界>的时候,被其绚丽的画面所折服,一个叫做贫瘠之地的 ...
- MYSQL进阶学习笔记十四:MySQL 应用程序优化!(视频序号:进阶_32)
知识点十五:MySQL 的应用程序优化(32) 一.访问数据库采用连接池 把连接当做对象或设备,统一放在‘连接池’里.凡是需要访问数据库的地方都从连接池里取连接 二.采用缓存减少对于MySQL的访问: ...
随机推荐
- zabbix 报错汇总
打开zabbix web界面点击profile出现以下报错信息: scandir() has been disabled for security reasons [profile.php:198 → ...
- 从jvm来看,scala中的@究竟是个什么鬼?@模式匹配符号(scala 词法分析 语法分析常用)
从jvm来看,scala中的@究竟是个什么鬼? 我也是初步尝试来看jvm的类文件,又是初次来分析@,如不对的地方,请各位指正! 先看一下@ 是个什么? object TestScala { def m ...
- storm介绍,核心组件,编程模型
一.流式计算概念 利用分布式的思想和方法,对海量“流”式数据进行实时处理,源自业务对海量数据,在“时效”的价值上的挖掘诉求,随着大数据场景应用场景的增长,对流式计算的需求愈发增多,流式计算的一般架构图 ...
- [LeetCode] 285. Inorder Successor in BST_Medium tag: Inorder Traversal
Given a binary search tree and a node in it, find the in-order successor of that node in the BST. No ...
- Genymotion虚拟镜像下载慢或者失败的解决办法
Genymotion虚拟镜像下载慢或者失败的解决办法 http://files2.genymotion.com/dists/8.0.0/ova/genymotion_vbox86p_8.0_18061 ...
- 11.2.0.4 RAC测试环境修改时区
当前问题: 系统时区修改后,集群数据库各个日志发现显示的还是之前时区的时间. 依据Linux (RHEL)修改时区更改了系统的时区后,集群数据库的各个日志还是显示之前的时区时间. 查找MOS资料 Ho ...
- php深入学习
关于PHP程序员解决问题的能力 http://rango.swoole.com/archives/340 深入理解PHP内核 by xuhong大牛 http://www.php-internals. ...
- Object-C-内存管理 对象生命周期
autoreleasepool 池子被销毁的时候被标记 autorelease 的对象调用一次release Person *p2=[[[Person alloc]init]autorelease]; ...
- EditPlus 4.3.2499 中文版已经发布(11月21日更新)
新的版本修复了如下问题: 文本库的日期快捷方式“^@”失效. 列选模式下“减少缩进量”命令无法执行. 在某些情况下突出显示匹配括号导致程序崩溃.(这个问题是我发现的,电邮告诉作者后,一天之内就修复了) ...
- Linux其他:环境变量配置
计算机==>右键==>属性==>高级系统设置==>环境变量==> 系统变量path后面+';python路径名