1.获取的是Point light的Light组件属性
2..注意other是谁,脚本放在谁上
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OffLight : 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")
{
Debug.Log("碰撞");
m_light.gameObject.SetActive(false);
}
}
}
本文介绍了一个简单的Unity脚本,该脚本通过检测碰撞来控制场景中的Pointlight组件的激活状态。具体而言,当名为'Switch'的游戏对象与包含脚本的物体发生碰撞时,Pointlight将被关闭。

1193

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



