【发布时间】:2016-11-18 06:23:20
【问题描述】:
我将聚光灯拖到主摄像头下方 并将 C# 脚本拖到聚光灯下。 但聚光灯不是相机所在的位置,也不是跟随角色移动。
这是我正在使用的脚本,它正在打开/关闭聚光灯:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
private Light myLight;
// Use this for initialization
void Start () {
myLight = GetComponent<Light>();
}
// Update is called once per frame
void Update () {
if(Input.GetKeyUp(KeyCode.F))
{
myLight.enabled = !myLight.enabled;
}
}
}
在此屏幕截图中,您可以看到地板上的聚光灯。我如何将它连接到角色或主相机,以便它与角色一起移动?
【问题讨论】:
-
没有代码可以显示吗?我猜这样会更容易给出提示。
-
@Dilettant 脚本?我会将它添加到我的问题中。到目前为止我所做的脚本只是关闭/打开聚光灯,它正在工作。
-
您可能希望在脚本中添加一个 FixedUpdate,您可以在其中使 Spotlight 变换等于相机变换(最终在位置上进行偏移,否则光源将是玩家的眼睛)。
标签: c# monodevelop unityscript unity5