1.这是完整的开关灯逻辑,之前为关灯
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OnOffLight : 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 OnCollisionEnter(Collision other) {
if (other.gameObject.name == "Switch") {
m_light.enabled = !m_light.enabled;
}
}
}
本文介绍了一个使用Unity实现的简单开关灯逻辑。该逻辑通过碰撞检测来改变指定光源的状态(开/关)。当名为'Switch'的对象与光源碰撞时,光源状态将会反转。
16万+

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



