蓝鸥Unity开发教程之课时5 Unity组件开发之脚本组件
2016-09-04 14:12
316 查看
蓝鸥Unity开发教程之课时5 Unity组件开发之脚本组件
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<Test> ();
t.age = 24;
t.name="HAHA";
t.Log ();
}
void Update () {
}
}
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<Test> ();
t.age = 24;
t.name="HAHA";
t.Log ();
}
void Update () {
}
}
相关文章推荐
- 蓝鸥Unity开发教程之课时5 Unity组件开发
- 蓝鸥Unity开发教程之课时6 脚本生命周期
- 蓝鸥Unity开发教程之课时1 下载并安装unity
- 蓝鸥Unity开发教程之课时9 Vector3
- C#开发Unity游戏教程之Scene视图与脚本的使用
- 【蓝鸥Unity开发基础三】课时5 Unity组件开发
- C#开发Unity游戏教程之Scene视图与脚本的使用
- 蓝鸥Unity开发教程之课时4 3D开发基础
- C#开发Unity游戏教程之使用脚本变量
- 蓝鸥Unity开发教程之课时15 Collider
- 蓝鸥Unity开发教程之课时8 GameObject
- 蓝鸥Unity开发教程之课时12 预设体
- C#开发Unity游戏教程之Scene视图与脚本的使用
- 蓝鸥Unity开发教程之课时14 刚体
- 蓝鸥Unity开发教程之课时16 碰撞事件
- 蓝鸥Unity开发教程之课时11 Time和Mathf类
- Unity 2D游戏开发教程之使用脚本实现游戏逻辑
- C#开发Unity游戏教程之使用脚本变量
- 蓝鸥Unity开发教程之课时2 游戏对象和基本操作
- 蓝鸥Unity开发教程之课时3 Terrain地形系统