慕课的教程http://www.imooc.com/video/12355
这里相当于做笔记而已
生命周期和周期的执行顺序
自己新建了一个项目
脚本执行顺序
后放上去的脚本先执行
想要调整脚本顺序也可以在监视窗口里面点击Script execution order,然后按顺序把脚本拖到default time中
创建物体
<code>
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
GameObject go;
// Use this for initialization
void Start () {
go = new GameObject ("new");
}
// Update is called once per frame
void Update () {
}
}
</code>
然后讲脚本挂到某个物体上,在启动之后就会生成名字为new的gameobject
gameobject是最基础的控件
获得控件
栗子(改变灯光的颜色)
首先自己创建一个3D的cube
然后把脚本放到Directional Light上
脚本里面写
<code>
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
GameObject go;
Light light;
// Use this for initialization
void Start () {
go = new GameObject ("new");
light = GetComponent<Light> ();
light.color = Color.red;
}
// Update is called once per frame
void Update () {
}
}
</code>
这样我们的light首先获取到了自身控件上的lighti脚本,然后让该脚本的color变成红色j
public栗子(脚本不在directional light上的改变颜色的办法)
把脚本挂到其他物体上,代码为
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
public Light light;
// Use this for initialization
void Start () {
//light = GetComponent<Light> ();
light.color = Color.red;
}
// Update is called once per frame
void Update () {
}
}
然后在挂载脚本的监控窗口里面会多了一个方块
直接把directional light这个控件拉进去
这样light就直接为directional这个控件上的Light脚本了
获取其他控件的方法
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
Light light;
GameObject golight;
// Use this for initialization
void Start () {
golight = GameObject.Find ("Directional Light");
light = golight.GetComponent<Light> ();
light.color = Color.red;
}
// Update is called once per frame
void Update () {
}
}
首先定义一个gameobject golight 然后找到dirction light这个控件
然后让light得到golight下的light脚本
=w=然后就可以啦
woc这样我们就可以继续水下模糊的制作了!!!