1, 名词空间
如果这个类的所属命名空间没有加进来,则单击右键,选Resolve-----》using System.Text;即可,其它类似。如下图所示。
2,变量声明
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class lightgaze : MonoBehaviour {
public GameObject cam;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.position = cam.transform.position;
transform.rotation = cam.transform.rotation;
//this.transform.LookAt (cam.transform.forward);
}
}
这样写cam在界面直接托这赋值,就不用再用之前申请空间了。
如果是通过查找Find函数找到则需要在用之前对对象分配空间。