Light灯光组件+组件的相关操作+游戏资源的加载

Light灯光组件

Type: Directional:平行光,模仿的是太阳光

Spot:聚光灯

Area:区域光

Color: 颜色值

Mode: RealTime:实时

Mix:混合

Baked:烘焙

Intersity: 光照强度

Indirect Multiplier:光照强度乘数

Shadow Type:影子设置: No Shadow 没有影子 Hard Shadow:硬影子 soft Shadow:柔和影子

cookie: (类似于)灯光上贴的一层纸 size;

Draw halo:辉光(个人认为类似于朦胧的月光感)

Culling Mask:裁剪层

组件的获取,添加,删除等操作

相关代码如下:

cs 复制代码
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A)){
            light1.type = LightType.Spot;
            light1.range = 20;
        }
        if (Input.GetKeyDown(KeyCode.B))
        {
            light1.type = LightType.Point;
            //组件的获取
            TestComponent tc = lightObj.GetComponent<TestComponent>();
            if (tc)
            {
                light1.range = tc.range;
            }
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            //组件的添加
            TestComponent tc = lightObj.AddComponent<TestComponent>();
            tc.age = 100;
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            //组件的销毁
            TestComponent tc2 = lightObj.GetComponent<TestComponent>();
            Destroy(tc2);
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            //组件的失活
            TestComponent tc3 = lightObj.GetComponent<TestComponent>();
            tc3.enabled = false;
        }
        if(Input.GetKeyDown(KeyCode.F)){
            //组件的激活
            TestComponent tc3 = lightObj.GetComponent<TestComponent>();
            tc3.enabled = true;
    }
游戏资源的加载

代码如下:

cs 复制代码
         if (Input.GetKeyDown(KeyCode.G))
        {
            //Project面板中Resources文件不能错任何字母和大小写
            //加载Resources文件夹中的资源,泛型加载
            GameObject go = Resources.Load<GameObject>("Prefab/Tank");
            //实例化游戏资源
            Instantiate(go);
            //方法2
            GameObject go1 = Resources.Load("Prefab/Tank") as GameObject;
            Instantiate(go1);
        }

运行结果如下,按G键clone出一个Tank预制体。

该系列专栏为网课课程笔记,仅用于学习参考。

相关推荐
土了个豆子的1 小时前
unity中的动画混合树
unity·游戏引擎
中游鱼1 小时前
C# 数组和列表的基本知识及 LINQ 查询
c#·linq·数组·数据处理·list数列
32码奴2 小时前
C#基础知识
开发语言·c#
奔跑的犀牛先生4 小时前
unity学习26:用Input接口去监测: 鼠标,键盘,虚拟轴,虚拟按键
unity
来恩100311 小时前
C# 类与对象详解
开发语言·c#
Dr.勿忘14 小时前
C#面试常考随笔8:using关键字有哪些用法?
开发语言·unity·面试·c#·游戏引擎
xcLeigh14 小时前
WPF进阶 | WPF 数据绑定进阶:绑定模式、转换器与验证
c#·wpf
谢大旭15 小时前
ASP.NET Core 中间件
后端·中间件·c#
存储服务专家StorageExpert15 小时前
答疑解惑:如何监控EMC unity存储系统磁盘重构rebuild进度
运维·unity·存储维护·emc存储
时光追逐者15 小时前
Visual Studio使用GitHub Copilot提高.NET开发工作效率
c#·github·.net·copilot·ai编程·微软技术·visual studio