Unity3d 我的代码.pdf
文本预览下载声明
FoxPDF TXT转换成PDF格式转换器 3.0 (未注册) | http://www.
/TXT-to-PDF-Converter/TXT-to-PDF-Converter.html
3)在MonoDevelop中编辑代码
using UnityEngine;
using System.Collections;
public class HelloWorld : MonoBehaviour {
/** 在屏幕显示 **/
void OnGUI() {
// 标签文本尺寸
GUI.skin.label.fontSize = 100;
// 标签(显示区域(x,y,w宽,h高),“显示文本”)
GUI.Label(new Rect(10, 10, Screen.width, Screen.height), HelloWorld!!
!);
}
}
2.为飞机添加脚本
1)创建脚本文件
using UnityEngine;
using System.Collections;
[AddComponentMenu(MyGame/Player)]
// 这个类名,即场景中角色的名称,也就是Hierarchy中的对象名
public class Player : MonoBehaviour {
/**
* 构造函数不可用于初始化
**/
// 基速度
public float m_speed = 1; // public类型的变量可以在Inspector中配置
// 每渲染一帧动画,即调用一次
void Update () {
float movev = 0; // 垂直方向速度
float moveh = 0; // 水平方向速度
// 向上箭头
if (Input.GetKey(KeyCode.UpArrow)) {
movev -= m_speed * Time.deltaTime;
}
/**
* Input包装输入功能,包括键盘、鼠标、触控
* Time.deltaTime表示每一帧被渲染的时刻,时长?
**/
FoxPDF TXT转换成PDF格式转换器 3.0 (未注册) | http://www.
/TXT-to-PDF-Converter/TXT-to-PDF-Converter.html
// 向下箭头
if (Input.GetKey(KeyCode.DownArrow)) {
movev += m_speed * Time.deltaTime;
}
// 向左
if (Input.GetKey(KeyCode.LeftArrow)) {
moveh += m_speed * Time.deltaTime;
}
// 向右
if (Input.GetKey(KeyCode.RightArrow)) {
moveh -= m_speed * Time.deltaTime;
}
// this即Player
this.transform.Translate(new Vector3(moveh, 0, movev));
/**
* 物理转换器
* this.transform调用游戏体的Transform组件
* Transform包装移动、旋转、缩放
* Vector3(x, y, z)
**/
}
}
2)创建子弹控制脚本
using UnityEngine;
using System.Collections;
[AddComponentMenu (MyGame/Rocket) ]
/**
显示全部