Unity - 3D -鬼屋 128 - 139
128 - 环境光遮挡&逐晕&镜头失真
官方教程项目系列/官方教程06_3D/John Lemon's Haunted Jaunt/05.后期处理.md · chutianshu/AwesomeUnityTutorial - Gitee.c...
128.1 环境光遮罩 Ambient Occlusion
- Thickness Modifier : 增大阴影
128.2 逐晕 Vignette
使摄像头镜头本身的边缘变暗.这有助于专注于玩家并使游戏感觉更幽闭恐怖.
128.3 镜头失真 Lens Distortion
镜头的凹凸.
129 - 设置游戏结束UI
129.1 创建 Image
创建 Image 会 直接创建 Canvas.
129.2 关闭特效
129.3 Img平铺
129.4 颜色
129.5 填图
Preserve Aspect : 保持原有比例
129.6 逻辑
默认不显示 , 游戏结束时淡入淡出地显示.
添加透明度
130 - 添加游戏结束代码逻辑
130.1 创建配置触发
130.2 新建脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class GameEndingController : MonoBehaviour
{private bool isPlayerAtExit;public GameObject player;public float fadeDuration = 1.0f; //渐隐时间private float timer; //计时器public float displayImageDuration = 1.0f;public CanvasGroup exitBackgroundImageCanvasGroup;private void OnTriggerEnter(Collider other){if (other.gameObject == player) { isPlayerAtExit = true;}}// Update is called once per framevoid Update() {if (isPlayerAtExit) { EndLevel();Debug.Log("退出游戏!!");}}void EndLevel() {timer += Time.deltaTime;exitBackgroundImageCanvasGroup.alpha = timer / fadeDuration;if (timer > fadeDuration + displayImageDuration) {//Application.Quit(); //结束当前应用程序 , 打包发布之后才能生效.UnityEditor.EditorApplication.isPlaying = false;}}
}
130.3 配置
131 - 加入石像鬼敌人
131.1 配置动画
131.1.1 创建 Animator Controller
131.1.2 加入Idle动画
131.2 配置石像鬼碰撞体
131.2.1 给石像鬼整体添加碰撞体
添加胶囊碰撞体 , 包裹模型.
131.2.2 添加空物体配置胶囊碰撞体
胶囊碰撞体模拟视野.
132 - 加入石像鬼代码
132.1 复制
复制上一节做好的 Canvas Image 为 被抓住 时的游戏结束UI.
132.2 代码
132.2.1 ObserverController.cs
public class ObserverController : MonoBehaviour
{public Transform player;private bool isPlayerRange;public GameEndingController gameEnding;private void OnTriggerEnter(Collider other){if (other.transform == player) {isPlayerRange = true;}}private void OnTriggerExit(Collider other){if (other.transform == player) {isPlayerRange = false;}}// Update is called once per framevoid Update(){if (isPlayerRange) {Vector3 direction = player.position - transform.position + Vector3.up;Ray ray = new Ray(transform.position, direction);RaycastHit raycastHit;//out 代表第二个参数是输出参数 , 可以带出数据到参数中if (Physics.Raycast(ray, out raycastHit)) {if (raycastHit.collider.transform == player){gameEnding.CaughtPlayer();}}}}
}
132.2.2 GameEndingController.cs
public class GameEndingController : MonoBehaviour
{private bool isPlayerAtExit;public GameObject player;public float fadeDuration = 1.0f; //渐隐时间private float timer; //计时器public float displayImageDuration = 1.0f;public CanvasGroup exitBackgroundImageCanvasGroup;//新增一个表示游戏失败的结束界面public CanvasGroup caughtBackgroundImageCanvasGroup;private bool isPlayerCaught;public void CaughtPlayer() {isPlayerCaught = true;}private void OnTriggerEnter(Collider other){if (other.gameObject == player) { isPlayerAtExit = true;}}// Update is called once per framevoid Update() {if (isPlayerAtExit){EndLevel(exitBackgroundImageCanvasGroup,false);Debug.Log("退出游戏!!");}else if (isPlayerCaught) {EndLevel(caughtBackgroundImageCanvasGroup, true);Debug.Log("被抓住了!");}}void EndLevel(CanvasGroup imageCanvasGroup , bool doRestart) {timer += Time.deltaTime;imageCanvasGroup.alpha = timer / fadeDuration;if (timer > fadeDuration + displayImageDuration) {//Application.Quit(); //结束当前应用程序 , 打包发布之后才能生效.if (doRestart) {//重新加载第一个场景SceneManager.LoadScene(0);}UnityEditor.EditorApplication.isPlaying = false;} }}
132.3 配置
134 - 添加巡逻幽灵
134.1 创建&添加动画
134.2 配置Ghost
134.2.1 添加碰撞体
134.2.2 添加刚体
- Is Kinematic : 受力但不运动
134.2.3 添加 视野用 collider
复制石像鬼的 PointOfView 对象 , 之后进行调整.
136 - 相对坐标 X 绝对坐标
默认子游戏物体的 Transform 坐标为相对 父物体 的 Local 坐标.
如果想要 子物体的 Transfrom 的位置 表示 Word的坐标,则把父物体的 Transfrom 0,0,0即可
137 - 添加非剧情音频
137.1 添加非剧情音乐
分别为 : BGM , 胜利时音效 , 游戏失败时音效.
137.2 创建 Audio Source 对象
BGM
胜利音效
失败音效
137.3 GameEndingController
public class GameEndingController : MonoBehaviour
{private bool isPlayerAtExit;public GameObject player;public float fadeDuration = 1.0f; //渐隐时间private float timer; //计时器public float displayImageDuration = 1.0f;public CanvasGroup exitBackgroundImageCanvasGroup;//新增一个表示游戏失败的结束界面public CanvasGroup caughtBackgroundImageCanvasGroup;private bool isPlayerCaught;/*** 音效*/public AudioSource exitAudio;public AudioSource caughtAudio;private bool hasAudioPlayed = false; public void CaughtPlayer() {isPlayerCaught = true;}private void OnTriggerEnter(Collider other){if (other.gameObject == player) { isPlayerAtExit = true;}}// Update is called once per framevoid Update() {if (isPlayerAtExit){EndLevel(exitBackgroundImageCanvasGroup,false,exitAudio); Debug.Log("退出游戏!!");}else if (isPlayerCaught) {EndLevel(caughtBackgroundImageCanvasGroup, true,caughtAudio);Debug.Log("被抓住了!");}}void EndLevel(CanvasGroup imageCanvasGroup , bool doRestart , AudioSource audioSource) {if (!hasAudioPlayed) {audioSource.Play();hasAudioPlayed = true;}timer += Time.deltaTime;imageCanvasGroup.alpha = timer / fadeDuration;if (timer > fadeDuration + displayImageDuration) {//Application.Quit(); //结束当前应用程序 , 打包发布之后才能生效.if (doRestart) {//重新加载第一个场景SceneManager.LoadScene(0);}UnityEditor.EditorApplication.isPlaying = false;} }
}
138 - 添加玩家脚步声
138.1 Lemon添加AudioSource
138.2 PlayerMovementController
if (isWalking){ //保证不是每帧都重头播放if (audioSource.isPlaying == false) {audioSource.Play();} }else { audioSource.Stop(); }
public class PlayerMovementController : MonoBehaviour
{/*** 移动*/private Vector3 m_Movement;private float horizontal;private float vertical;private Rigidbody rigidbody;/*** 动画*/private Animator animator;/*** 转向*/Quaternion rotation = Quaternion.identity; //四元数 public float rotateSpeed = 20.0f; //角速度/*** 音效*/private AudioSource audioSource;// Start is called before the first frame updatevoid Start(){rigidbody = this.GetComponent<Rigidbody>();animator = this.GetComponent <Animator>();audioSource = this.GetComponent<AudioSource>();}// Update is called once per framevoid Update(){/*** 获取用户输入*/horizontal = Input.GetAxis("Horizontal");vertical = Input.GetAxis("Vertical");}private void FixedUpdate(){m_Movement.Set(horizontal, 0.0f, vertical);m_Movement.Normalize();bool hasHorizontal = !Mathf.Approximately(horizontal, 0.0f);bool hasVertical = !Mathf.Approximately(vertical, 0.0f);bool isWalking = hasHorizontal || hasVertical;if (isWalking){ //保证不是每帧都重头播放if (audioSource.isPlaying == false) {audioSource.Play();} }else { audioSource.Stop(); }animator.SetBool("isWalking", isWalking);/*** 旋转* p1 : current* p2 : target* p3 : maxRadiansDelata ,radians : 弧度 : 此旋转允许的最大角度* p4 : maxMagnitudeDelata : 此旋转允许的最大矢量幅度变化*/Vector3 desiredForward = Vector3.RotateTowards(transform.forward, m_Movement, rotateSpeed * Time.deltaTime, 0.0f);rotation = Quaternion.LookRotation(desiredForward); //设置四元数}private void OnAnimatorMove() //事件 : 当动画播放引发根移动时执行{rigidbody.MovePosition(rigidbody.position + m_Movement * animator.deltaPosition.magnitude);rigidbody.MoveRotation(rotation);}
}
139 - 幽灵音效
139.1 调换 Audio Listener
139.2 配置 Audio Source
139.3 优化
当 Lemon 转动时, 音频监视器(Audio Listener)也会随之转动,这意味着,当Lemon面向屏幕时,玩家的虚拟眼睛(摄像机)和玩家的虚拟耳朵(Audio Listener)将面向不同方向.因此听起来,鬼魂就在对面
让我们结合两个使用属性,使幽灵的声音没有方向性,但随着幽灵的靠近,声音会变大.
139.3.1 单声道
139.3.2 Speard
Unity - 3D -鬼屋 128 - 139相关推荐
- 物联网技术周报第 143 期: Unity 3D 和 Arduino 打造虚拟现实飞行器
新闻 \\ \\t <西门子.阿里云签约助力中国工业物联网发展>德国工业集团西门子和中国阿里巴巴集团旗下的云计算公司阿里云9日在柏林签署备忘录,共同推进中国工业物联网发展.根据备忘录内容, ...
- [Unity 3D] 簡單瞭解「Collision碰撞」與「Trigger觸發」
Unity 3D是套非常好用的遊戲開發引擎, 內建的物理系統讓使用者不需寫長長的程式碼, 就能夠迅速設定好所有物件之間的碰撞關係, 做出讓角色走不過去的牆.或是可以射穿牆壁的子彈等等. 不過它的設定相 ...
- 文献 | 去鬼屋和看恐怖片的恐惧情绪是相同的吗?
Hello,大家好. 这里是壹脑云科研圈,我是喵君姐姐- 恐惧一直是我们很重要的情绪,有些小伙伴在去鬼屋时会吓得心惊肉跳,但看恐怖片时却不那么害怕,难道二者的恐惧情绪是不一样的吗? 结果是不一样的! ...
- Unity 3D : ComputeShader 全面詳解
Unity 3D : ComputeShader 全面詳解 https://blog.csdn.net/weixin_38884324/article/details/80570160 前言: 會寫一 ...
- Unity 3D学习视觉脚本无需编码即可创建高级游戏
在本课程中,您将学习如何在Unity中使用可视化脚本(以前称为Bolt)以及如何在不编写一行代码的情况下创建自己的高级游戏所需的一切.本课程将教你如何掌握可视化脚本,即使你以前没有任何关于unity或 ...
- Unity三维游戏开发C#编程大师班 Masterclass In C# Programing Unity 3D Game Development FPS
本课程采用现代游戏开发(Unity 2021)的最新内容和最新技术 学习任何东西的最好方法是以一种真正有趣的方式去做,这就是这门课程的来源.如果你想了解你看到的这些不可思议的游戏是如何制作的,没有比这 ...
- Unity 3D为策略游戏创建地图学习教程
MP4 |视频:h264,1280×720 |音频:AAC,44.1 KHz,2 Ch 语言:英语+中英文字幕(根据原英文字幕机译更准确) |时长:30节课(7h 42m) |大小:5 GB 含项目文 ...
- Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D C#: Learn To Code Making 3D Games
Unity 3D游戏代码编程学习教程 Full Guide To Unity 3D & C#: Learn To Code Making 3D Games Full Guide To Unit ...
- 聊聊在博客园写博客的这两年《Unity 3D脚本编程:使用C#语言开发跨平台游戏》正式出版...
版本状态: 2016.9 第一次印刷 (2016.11 输出到台湾) 2017.1 第二次印刷 2017.5 第三次印刷 2017.5 电子书上线:Unity 3D脚本编程--使用C#语言开发跨平台游 ...
最新文章
- 【Linux】一步一步学Linux——hexdump命令(267)
- DataURL:实现原理及优缺点分析
- Oracle第三课之PLSQL
- c语言程序设计黄保和第二章,C语言程序设计答案(黄保和编)第6章
- 【JAVA 第五章 】课后习题 奇数排前
- 奈飞文化集:自由与责任_如何与自由客户合作:最好的合同就是您永远不必执行的合同...
- java 陷阱_Java基础知识陷阱
- Ubuntu卸载图形界面
- 基础之 window-self-top-opener
- javaweb框架和其他知识点总结
- turtle实例2 奥运五环
- 如何理解P和NP问题
- windows中git输错密码后不能重新输入的问题
- “圆周率的计算”实例详解
- 猜价格游戏c语言课程设计,肿么用C#编写一个猜价格的小程序?
- 【OSPF外部路由-4类LSA(sum-asbr)和5类LSA(external)以及7类LSA(Nssa)】(OSPF的特殊区域)(外部路由选路特性)
- moviepy音视频开发:使用credits1给视频加片头片尾字幕
- PHP之流程控制(四)
- Azure SQL 数据库连接字符串
- 多子群改进的海洋捕食者算法-附代码