0
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Characters.ThirdPerson;
public class Flashlight : MonoBehaviour {
Light flashlight;
// Use this for initialization
void Start()
{
flashlight = GetComponent<Light>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (flashlight.enabled)
{
flashlight.enabled = false;
}
else
{
flashlight.enabled = true;
}
}
}
}
因为我在层次结构中有其他Light组件,所以我在手电筒对象上添加了一个名为Flashlight的标签。我如何通过标签找到Light组件?
但是我如何才能通过手电筒标签获得正确的光?
我所做的:手电筒= GameObject.FindGameObjectWithTag( “手电筒”);但得到错误: 错误不能隐式地将类型'UnityEngine.GameObject'转换为'UnityEngine.Light' –
再次检查我的答案:) – Hristo
非常感谢:) –