[英]How can i find the Light component by tag?
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的標簽。
但是,如何通過Flashlight標簽獲取正確的光源?
void Start ()
{
flashlight = FindGameObjectsWithTag("FlashLight").GetComponent<Light>();
}
從這里引用
您可以創建一個公共場所或一個吸氣劑,從中選擇確切的參考
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.