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;
}
}
}
}
Since i have other Light components in the Hierarchy i added a tag to the flashlight object called it Flashlight.
But how can i get the correct Light by the Flashlight tag ?
void Start ()
{
flashlight = FindGameObjectsWithTag("FlashLight").GetComponent<Light>();
}
Referenced from here
您可以创建一个公共场所或一个吸气剂,从中选择确切的参考
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.