Step1:添加后期处理效果--抗锯齿效果
有点类似高级的photoshop 创建风格化的视觉效果
渲染管线:
执行一系列操作还获取场景的内容
添加抗锯齿特效 添加在摄像头上
在层上添加PostProcessingVolumes
设置一个新的组件,添加到maincamera
添加post-process layer,选择Layer Post...
Mode 选择 FXAA
勾选 FastMode
效果是:线条柔和了很多
Step2: 创建处理后期体积的特效
创建空的游戏对象
层设置为后期处理层
添加提及组件 post ... volume
position 定位到原点
添加配置文件 new 一个 位置在Scene
点击Add effect,选中color grading
记得要勾选 Is Global
打开Tonemapping 选择 ACES
Post-exposure 变成 1
Trackballs 轨迹球
改变Lift Gamma Gain
添加泛光特效 创建延申的光条纹
添加Bloom
Intensity 1
Threshold 0.75
Step3: 增加特效
增加环境光遮罩
增添 Ambient Occlusion
Intensity 0.5
Thickness 3.5
在摄像头上添加 Vignette 效果
Intensity 0.5
Smoothness 0.3
添加镜头失真特效 Lens distortion
intensity 35
scale 1.1
Step4:结束游戏设置
选中层级界面
create - UI - Image
删除Event
选中 canvas 调整render mode
调整视角,聚焦Canvas
删掉 canvas scaler 以及下一个组件
Image名字改为ExitImageBackground
定位 Anchors
Min 0 0
Max 1 1
Left Top Posz
0 0 0
Color 背景调成纯黑色
显示结束图像
添加ExitImage
添加Image 然后平铺
勾选 Preserve Aspect
让它默认情况下不显示,
在外层图像,增加Canvas Group(控制游戏对象以及子项)
Alpha 0
Step5:触发器添加
新建GameEnding
添加box collider
勾选Is Trigger
在transform里更改位置 18 1 1.5
Size 1 1 3.5
在scripts 创建脚本 GameEnding
// 调用结束UI ,展示胜利画面
// 设置计时器,到指定时间,退出游戏
// 步骤1,应该写入触发器事件
// 步骤2,应该将游戏结束的操作,写入一个自定义的函数(方法)
// 在Update中,使用一个开关来判断是否调用游戏相关的函数
// 而这个开关变量,就是玩家是否已经进入结束区域
结束界面的一个展示
Step6:添加敌人 -- 静态石像鬼
制作石像鬼的预制件 Gargoyle
在animators 创建Gargoyle
增加碰撞体和触发器
Capsule Collider
radius 0.3
Heigyht 1.8
Y:0.8
选中预制件,PointOfView
按照教程调整参数
挂接失败的图片
复制一份成功的图片,然后更改图片参数
将对应的脚本文件拖入到对应的框内,然后运行
Step7:添加敌人 --- 幽灵
添加动画controller,然后再增加动画
添加碰撞体和刚体
capsule collider 更改大小
Height:1.2
Y:0.6
Radius:0.25
Step8:设置Nav Mesh Agent设置幽灵移动
选中ghost 添加Nav Mesh Agent
Speed 1.5
radius 0.25
Height 1.2
添加脚本组件 WaypointPatrol
-5.3 0 -3.1
1.5 0 4
3.2 0 6.5
7.4 0 -3
-5.3 0 6.7
-5.5 0 -4.5
1.2 0 7.7
0.9 0 -3.5
3.2 0 5.6
3.2 0 2.3
6.5 0 12.3
6.5 0 5.6
3.2 0 -5
7.4 0 -2
-2.6 0 -8.5 0 30 0
-4.8 0 10.6
-4.8 0 10.6 0 101 0
WayPointPatrol 巡逻幽灵代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WaypointPatrol : MonoBehaviour
{
// Start is called before the first frame update
UnityEngine.AI.NavMeshAgent navMeshAgent;
public Transform[] waypoints;
int m_CurrentWaypointIndex;
void Start()
{
navMeshAgent = GetComponent<UnityEngine.AI.NavMeshAgent>();
navMeshAgent.SetDestination(waypoints[0].position);
}
// Update is called once per frame
void Update()
{
if(navMeshAgent.remainingDistance < navMeshAgent.stoppingDistance)
{
m_CurrentWaypointIndex = (m_CurrentWaypointIndex + 1) % waypoints.Length;
navMeshAgent.SetDestination(waypoints[m_CurrentWaypointIndex].position);
}
}
}
视线代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Observer : MonoBehaviour
{
// Start is called before the first frame update
public Transform player;
bool m_IsPlayerInRange;
public GameEnding gameEnding;
//触发器事件
//玩家进入实现触发器区域,更改开关值
private void OnTriggerEnter(Collider other)
{
if(other.transform == player)
{
m_IsPlayerInRange = true;
}
}
private void OnTriggerExit(Collider other)
{
if(other.transform == player)
{
m_IsPlayerInRange = false;
}
}
// Update is called once per frame
void Update()
{
if(m_IsPlayerInRange)
{
Vector3 direction = player.position - transform.position;
Ray ray = new Ray(transform.position, direction);
RaycastHit raycastHit;
if(Physics.Raycast(ray,out raycastHit))
{
if(raycastHit.collider.transform == player)
{
gameEnding.CaughtPlayer();
}
}
}
}
}
UI界面代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameEnding : MonoBehaviour
{
// Start is called before the first frame update
bool m_IsPlayerAtExit;
bool m_IsPlayerCaught;
public GameObject player;
//更改透明度的一个时间
public float fadeDuration = 1.0f;
//计时器
float m_Timer;
//正常(完全不透明状态)显示UI界面的时间
public float displayImageDuration = 1.0f;
public CanvasGroup exitBackgroundImageCanvasGroup;
public CanvasGroup caughtBackgroundImageCanvasGroup;
void OnTriggerEnter(Collider other)
{
if (other.gameObject == player)
{
//将开关设置为true
m_IsPlayerAtExit = true;
}
}
public void CaughtPlayer()
{
m_IsPlayerCaught = true;
}
// Update is called once per frame
void Update()
{
//如果用户进入结束祺禹,调用结束游戏相关方法
if (m_IsPlayerAtExit)
{
EndLevel(exitBackgroundImageCanvasGroup,false);
}
else if(m_IsPlayerCaught)
{
EndLevel(caughtBackgroundImageCanvasGroup, true);
}
}
//结束当前关卡
void EndLevel(CanvasGroup imageCanvasGroup,bool doRestart)
{
//计时器随着Update增大
//结束当前应用程序,打包发布时才能生效
m_Timer += Time.deltaTime;
imageCanvasGroup.alpha= m_Timer / fadeDuration;
if (m_Timer > fadeDuration + displayImageDuration)
{
if (doRestart)
{
SceneManager.LoadScene(0);
}
else
{
// Application.Quit();
UnityEditor.EditorApplication.isPlaying = false;
}
}
}
}
大佬是想做游戏开发吗
嗯嗯,现在先补齐基础知识
嘤嘤嘤