获取Component方式
1.直接将脚本挂载到 Light上,可以直接getComponent方式获取。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
GameObject go;
Light light;
// Use this for initialization
void Start () {
go = new GameObject("name");
//脚本挂载在Directional Light下,获取light方式
light = GetComponent<Light>();
light.color = Color.green;
}
// Update is called once per frame
void Update () {
}
}
2.挂载在其他GameObject上,获取Light,可将脚本Light设置为public属性,脚本上拖动相应组件到上面
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour {
GameObject go;
public Light light;
// Use this for initialization
void Start () {
go = new GameObject("name");
light.co