【问题标题】:How can i connect a spotlight to main camera so when moving character the spotlight will move with it?如何将聚光灯连接到主摄像机,以便在移动角色时聚光灯会随之移动?
【发布时间】: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


【解决方案1】:

尝试将聚光灯的Transform localPosition设置为0.0, 0.0, 0.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-06-30
    • 1970-01-01
    • 2015-06-09
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    相关资源
    最近更新 更多