【发布时间】:2019-09-26 16:19:02
【问题描述】:
在我的 Unity 2D 游戏中,我有一个带有光源组件的角色 Lightweight RP 包中的“Light 2D(Script)”。
我想用下面的代码改变 Light 2D 的强度。
但我无法在 Unity Inspector 面板中将“Light 2D(Script)”分配给 public Light LightSource。
我尝试过使用 public Light2D LightSource 类,但它似乎不存在。
还有其他方法可以访问 2D Light 组件还是我做错了什么? 如果有帮助,我还添加了 Inspector 窗格的屏幕截图。
如果您需要更多信息,请告诉我,我希望有人可以提供帮助。谢谢
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Lighting : MonoBehaviour
{
public Light LightSource;
public float lightIntensity;
public float minIntensity = 0.35f, maxIntensity = 0.65f;
void Update()
{
lightIntensity = Random.Range(minIntensity, maxIntensity);
LightSource.intensity = lightIntensity;
}
}
【问题讨论】:
-
你有什么错误,你在编辑器中连接了Light吗?
-
您的问题不是很清楚您在场景中实际拥有什么。截图会有很大帮助。无论如何尝试将行从
public Light LightSource;更改为public Light2D LightSource;,然后在检查器中将Light2D组件拖到它上面。 -
是的,可能是通过使用正确的字段类型...虽然我不知道任何
Light2D类,它也没有出现在 API 中。你从哪里得到的? -
@derHugo 我也不确定,但我假设它可能是the LWRP Light2D Component
-
@Ruzihm 或 this ;) 但是是的,你的接缝更近了