Unity3D学习记录——触发器开关灯

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();
	}
	
	// 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)