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
非常感謝:) –