Unity笔记 Stealth 实例详解
来源:互联网 发布:java中1到100的质数 编辑:程序博客网 时间:2024/06/18 06:10
第一部分
http://unity3d.com/learn/tutorials/projects/stealth-tutorial-4x-only
1 介绍
一个3D项目,初、中级难度
2 添加环境模型、光照贴图lightmap
lightmapping:
设置static模型,才可以使用lightmap。
extents选layer->extent。 别的选在layer-> playarea。
打开fog 调整quality
bake lightmapping:
先bake low quality,pad选择2。
场景中的main和alarm两个光设置为realtime不参与bake lightmapping
3 警报灯
用脚本控制警报的intensity,制作一闪一闪(pulse)的效果。
添加了一个音原到扩音器(megaphone)
4 管理tag
一些全局静态字符串,方便以后在代码各处使用。
public class Tags : MonoBehaviour{ // A list of tag strings. public const string player = "Player"; public const string alarm = "AlarmLight"; public const string siren = "Siren"; public const string gameController = "GameController"; public const string mainLight = "MainLight"; public const string fader = "Fader"; public const string enemy = "Enemy";}
5 屏幕fade效果
用一张黑色图片控制alpha值来全屏遮挡。
build时,添加场景到build list,会自动递增一个index给这个scene。
6 GameController
GameController管理游戏内通用的一些行为(目前是播放音乐和角色位置管理)。
建立一个GameController空物体,可以加normalmusic音源和insight脚本检测玩家被发现时的位置。
加入panic音源做为子物体,做为被发现时的背景音。
7 闭路电视
加入模型,勾选use light probes。加入个截头体模型做碰撞用。
可视化用spotlight发出红色的光,并设置realtimeonly,设置cookie(投影纹理)。
添加脚本,检查玩家是不是被看到。
设置insight脚本成员:
lastPlayerSighting = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent();
添加cctvsweep动画,来移动摄像机。在animation窗口中选好时间后点击添加关键帧。选择pingpong插值方式,这样可以只用2帧来建立一个循环动画。
8 激光
激光门:
添加模型,添加碰撞体,点击istrigger。
添加自发光,类似cctv也是realtimeonly。
添加blinking脚本,来触发insight改变场景状态。
激光门开关:
添加2个碰撞体,一个用于避免重合,另外一个触发开关。
scripts可以添加子文件夹,便于组织脚本。
第二部分
1 建立player
导入模型,受到light probes影响。
添加胶囊碰撞体。
在rigidbody 中 freeze rotation x y z(避免物理旋转) 和 position y(避免y方向位移)
移除camera上的listener,并在player上添加audio listener。
2 Player AC
float paramater的使用,speed。
bool paramater的使用, sneaking dead shouting。
建立localmotion blendtree。添加2个motion,walk和run。取消automatic thresholds,选择speed来计算thresholds。
建立从idle到localmotion的transtion,设置condition,speed greater 0.1, sneaking false。
添加sneaking,做transtion和条件。
anystate的使用,可以用它来做die。
新建avatar mask(独立文件)来叠加shout,在ac中新建layer:shouting,选择mask,这样就可以在脚本中调用这个layer了,建立emptystate 和 shout 2个状态,shout in transtion是通过shouting这个bool,shout out transtion是默认的exit time。
3 hash id
建立一个ac的string to hashid的脚本,这样高效且不容易出现字符串拼写失误。
using UnityEngine;using System.Collections;public class HashIDs : MonoBehaviour{ // Here we store the hash tags for various strings used in our animators. public int dyingState; public int locomotionState; public int shoutState; public int deadBool; public int speedFloat; public int sneakingBool; public int shoutingBool; public int playerInSightBool; public int shotFloat; public int aimWeightFloat; public int angularSpeedFloat; public int openBool; void Awake () { dyingState = Animator.StringToHash("Base Layer.Dying"); locomotionState = Animator.StringToHash("Base Layer.Locomotion"); shoutState = Animator.StringToHash("Shouting.Shout"); deadBool = Animator.StringToHash("Dead"); speedFloat = Animator.StringToHash("Speed"); sneakingBool = Animator.StringToHash("Sneaking"); shoutingBool = Animator.StringToHash("Shouting"); playerInSightBool = Animator.StringToHash("PlayerInSight"); shotFloat = Animator.StringToHash("Shot"); aimWeightFloat = Animator.StringToHash("AimWeight"); angularSpeedFloat = Animator.StringToHash("AngularSpeed"); openBool = Animator.StringToHash("Open"); }}
4 player移动
设置ac layer的权 anim.SetLayerWeight(1, 1f); shouting layer index is 1
旋转player
void Rotating (float horizontal, float vertical) { // Create a new vector of the horizontal and vertical inputs. Vector3 targetDirection = new Vector3(horizontal, 0f, vertical); // Create a rotation based on this new vector assuming that up is the global y axis. Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up); // Create a rotation that is an increment closer to the target rotation from the player's rotation. Quaternion newRotation = Quaternion.Lerp(rigidbody.rotation, targetRotation, turnSmoothing * Time.deltaTime); // Change the players rotation to this new rotation. rigidbody.MoveRotation(newRotation); }
通过speed和AC机制来控制播放动画,动画中的位移会被应用到player。
通过AC调整动画播放速度。
5 Player 血量
集合了很多要用到的东西,在死的时候调用
private Animator anim; // Reference to the animator component. private PlayerMovement playerMovement; // Reference to the player movement script. private HashIDs hash; // Reference to the HashIDs. private SceneFadeInOut sceneFadeInOut; // Reference to the SceneFadeInOut script. private LastPlayerSighting lastPlayerSighting; // Reference to the LastPlayerSighting script. private float timer; // A timer for counting to the reset of the level once the player is dead. private bool playerDead; // A bool to show if the player is dead or not.
用一个bool来控制dying只调用一次,dead在update中反复调用。
第3部分
1 camera
在awake中建立一些camera的relative位置信息,这些是在编辑模式编辑的。
建立一个标准摄像机和一个高位摄像机(above),并在这2个摄像机中插值3个。用这5个摄像机逐个检测,发现有合适的就采用。例如靠墙站立,摄像机就会选择高位。
2 钥匙
inventory script加在玩家身上来看玩家是不是拥有key,
keypickup script在设置inventory有key后Destroy(gameObject);来摧毁自己。
在mesh render点选use light probes
- Unity笔记 Stealth 实例详解
- Unity学习之Stealth学习笔记
- Unity官方示例教程《Stealth》学习笔记
- Unity笔记 2D ROGUELIKE 实例详解
- Unity笔记 SPACE SHOOTER 实例详解
- 官方教程Stealth学习笔记(一)
- unity官方demo学习之Stealth(一)
- unity官方demo学习之Stealth(三)标签管理
- unity官方demo学习之Stealth(五)游戏控制器
- unity官方demo学习之Stealth(七)激光门
- unity官方demo学习之Stealth(十一)角色移动
- unity官方demo学习之Stealth(十三)摄像机跟踪
- unity官方demo学习之Stealth(十六)双层门
- 实例详解Unity各种坐标的转换
- unity官方demo学习之Stealth(六)CCTV监控摄像机
- unity官方demo学习之Stealth(二)警报灯设定
- unity官方demo学习之Stealth(四)屏幕渐变效果
- unity官方demo学习之Stealth(八)角色初步设定
- light 1011 状态压缩dp
- PHP:empty,isset,is_null,array(0),array(),array(""),0,"0","","null",NULL的总结
- Java多线程系列--“JUC锁”03之 公平锁(一)
- Spring AOP 使用注解为API引入新功能
- cloudstack_template_snapshot_volume
- Unity笔记 Stealth 实例详解
- Codeforces 148 D Bag of mice(概率DP)
- Virtualbox虚拟机网络配置(NAT + Host-only - Bridged)
- iOS中NSArray, NSSet, NSDictionary的使用
- linq用法
- 智捷课堂改版啦!
- C++笔记
- 如何做出完美的APP?
- 关于虚拟字符设备驱动的学习笔记globalmem