栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > Unity3D

【学习记录——unity 3D】Stealth秘密行动游戏制作(一)

Unity3D 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【学习记录——unity 3D】Stealth秘密行动游戏制作(一)

提示:资源下载

文章目录
  • 一、场景搭建

一、场景搭建

1.在这里直接使用文件中的场景Prefebs–env_stealth_static
将其拖入Scenes中,重命名为environment
修改场景初始位置与摄像机的位置(即人物角色后续出生点)

在environment的属性面板中给其加入碰撞体
Mesh Collider下Mesh直接拖入资源包中制作好的碰撞体

2. 为了使游戏环境氛围更加具有紧张感
我们改变一下背景色和主光源
增加一些灯光

在Main camera组件中的camera属性将Clear Flags中的Skybox(天空盒子)换成Soild Color(固定色)
在Background中选择合适的背景色

效果差不多就是下图的样子,主要改变了模型之外摄像机能够拍到的背景色
修改主光源的颜色能够大大地改变游戏氛围
我这里新建了一个空物体命名为Light
在Light下新建子物体Light–Directional light

我这里修改成深蓝色,效果如下

下一步我们给场景中的小空间增加一些小光源,保证后续玩家进行游戏时,能够识别场景特征
以下光源均为点光源,可自行摆放设置
也可直接使用资源包中的光源(Prefebs–lights_baked)
拖入Scenes中与environment对齐即可

效果如下:

制作警报灯
在Light下新建子物体Light–Directional light
命名为Alarm Light
颜色修改为红色,我这里把Intensity(强度)改成了0.7,不会太刺眼

下面我们开始编写脚本来控制Alarm Light的闪烁
新建一个文件夹命名为Scripts,新建脚本AlarmLight

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AlarmLight : MonoBehaviour
{
    public float highIntensity=4f; //亮起时的最高亮度
    public float lowIntensity=0.4f;  //亮起时的最低亮度
    public float fadeSpeed = 2.0f;  //灭灯的速度

    public bool AlarmOn;

    private float targetIntensity; //目标亮度
    private Light alarmLight;  //当前场景中的警报灯对象

    // Start is called before the first frame update
    private void Awake()
    {
        alarmLight = GetComponent();
        alarmLight.intensity = 0f;
        targetIntensity = highIntensity;
    }

    // Update is called once per frame
    void Update()
    {
        if (AlarmOn)
        {
            alarmLight.intensity = Mathf.Lerp(alarmLight.intensity, targetIntensity, Time.deltaTime*fadeSpeed);
            if (Mathf.Abs(alarmLight.intensity - targetIntensity) < 0.03f)
            {
                if(highIntensity==targetIntensity)
                    alarmLight.intensity = lowIntensity;
                else
                    alarmLight.intensity = highIntensity;
            }
            //float res = Mathf.Lerp(10, 20, t);
            //Debug.Log(res.ToString());
        }
        else
        {
            alarmLight.intensity = Mathf.Lerp(alarmLight.intensity,0f, Time.deltaTime * fadeSpeed);
        }
    }
}

将此脚本拖到Alarm Light组件上,测试发现红灯每两秒闪烁一次

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/899513.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号