[英]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.