蓝鸥Unity入门脚本组件学习笔记

unity3D-游戏/AR/VR在线学习 蓝鸥Unity入门脚本组件学习笔记

脚本组件

在属性面板添加new script 然后创建一个脚本,语言选择C#,然后添加,双击打开脚本!

脚本要要挂载到游戏对象上,Text脚本必学继承MonBehaviour

Test脚本
using UnityEngine;
using System.Collections;

//如果我们的脚步需要挂载到游戏对象身上,就需要继承于MonoBehaviour
public class Test : MonoBehaviour {

public int age;
public string name;
public void Log(){
print(age+name);
}
void Start () {
//gameObject表示当前脚本组件所挂载的游戏对象
//unity中输出到控制台使用Print或者Debuq.log
// print("Test 脚本挂载到了"+gameObject.name+"的身上");
//每个游戏对象身上,都至少有一个组件,叫做Transform
//transform表示当前游戏对象身上的,Transform组件
// print(transform.position.x);
// print(age+name);
}
void Update () {
}
}

Dome脚本
using UnityEngine;
using System.Collections;

public class Dome : MonoBehaviour {

void Start () {
//GameObject的方法GetComponent能够获取当前游戏对象身上制定的类型的组件
Test t  =GetComponent ();
t.age = 24;
t.name="HAHA";
t.Log ();
}
void Update () {
}
}



你可能感兴趣的:(Unity3D开发)