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预制体。

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

相关推荐
就是有点傻9 小时前
C#中Tcp断线重连的两种方法
网络·tcp/ip·c#
云空10 小时前
经纬度计算距离
java·python·算法·c#
萌萌的提莫队长10 小时前
Unity XR PICO 手势交互 Demo APK
unity·游戏引擎·xr
什么问题11 小时前
重置SteamVR
unity·vr
逐·風16 小时前
Lua 代码优化
开发语言·前端·unity·lua
小白鼠零号16 小时前
记录|Modbus-TCP产品使用记录【四川零点】
c#·modbus·modbus-tcp
小吴同学·19 小时前
C#语言基础
c#
martian66519 小时前
C# WebApi 接口测试工具:WebApiTestClient应用技术详解
开发语言·测试工具·c#
@Sunset...20 小时前
热更新解决方案2 —— Lua语法相关知识点
开发语言·unity·游戏引擎·lua