计算机游戏程序设计实验指导书实验一.doc计 算机 游戏 程序 设计
实验指导书
实验一 GUI 游戏界面的实现
一、实验目的与要求
熟悉及掌握 GUI 的高级控件,以及用法。
掌握 GUI 自定义皮肤用法
熟悉 GUILayout 的使用。
熟悉 2D贴图的绘制和帧动画的实现方法。
二、实验内容及步骤
熟悉 GUI 高级控件,练****使用 GUI 的高级控件制作 2~3 个游戏界面。
练****使用 GUI 自定义皮肤, 实现游戏界面的字体, 背景颜色等设置。
熟悉 GUILayout 的使用,联系使用 GUILayout 的水平线性布局和垂直线性布局,并加适当偏移。
熟悉 2D贴图的绘制和帧动画的实现方法, 练****在界面中绘制静态图
片和动画。
三、实验仪器与软件
PC 计算机
2. Unity 3D 软件
四、实验报告要求
熟悉 GUI 高级控件,练****使用 GUI 的高级控件制作 2~3 个游戏界面。
Label 控件:
using UnityEngine;
using ;
public class kongjian : MonoBehaviour {
public Texture imageTexture;
private int imageWidth;
private int imageHeight;
1
private int screenWidth;
private int screenHeight;
Use this for initialization void Start () {
得到屏幕宽高
screenWidth = ;
screenHeight = ;
得到图片宽高
imageWidth = ;
imageHeight = ;
}
void OnGUI(){
将文字内容显示在屏幕中
(new Rect(100, 10, 100, 30), "hello unity");
将贴图显示在屏幕中
(new Rect(100, 120, imageWidth, imageHeight),imageTexture);
}
Update is called once per frame void Update () {
}
}
2
Button
using UnityEngine;
using ;
public class kongjian : MonoBehaviour {
public Texture buttonTexture;
private string str;
// Use this for initialization
void Start () {
str="请点击按钮! ";
}
void OnGUI(){
(new Rect(10, 10, , 30), str);
if((new
Rect(10,50,,),buttonTexture)){
点击按钮修改提示信息
str = " 您点击了图片按钮 ";
}
设置按钮中文字的颜色
3
= ;
设置按钮的背景色
= ;
}
Update is called once per frame void Update () {
}
计算机游戏程序设计实验指导书实验一 来自淘豆网www.taodocs.com转载请标明出处.