using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnOffLight2 : MonoBehaviour {
private Light m_light;
// Use this for initialization
void Start () {
m_light = GameObject.Find("Point light").GetComponent<Light>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.name == "Player") {
m_light.enabled = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.name == "Player")
{
m_light.enabled = false;
}
}
}
Unity3D学习记录——触发器开关灯
最新推荐文章于 2025-12-17 14:24:38 发布
本文介绍了一个使用Unity引擎实现的简单脚本,该脚本能够根据玩家角色是否进入指定触发区域来控制场景中灯光的开启与关闭。此功能通过两个Unity事件函数OnTriggerEnter和OnTriggerExit实现。
2万+

被折叠的 条评论
为什么被折叠?



