unity3d 第四天

来源:互联网 发布:彩票号码组合软件 编辑:程序博客网 时间:2024/05/18 17:02

Slider控件

value=GUI.VerticalSlider(postion,float,float,float);

value=GUI.HorizontalSlider(postion,float,float,float);


slider_test.cs

using UnityEngine;using System.Collections;public class Slider_test : MonoBehaviour {float verticalValue = 0.0f;float horizontaValue = 0.0f;// Use this for initializationvoid OnGUI(){//计算滑动进度verticalValue = GUI.VerticalSlider ( new Rect(25,25,30,100),verticalValue,100.0f,0.0f); //上 下  滑动指针停留在值最小的一边horizontaValue = GUI.HorizontalSlider (new Rect (50,25,100,30),horizontaValue,0.0f,100.0f);//左 右//将滑动进度显示在屏幕中GUI.Label(new Rect(10,180,Screen.width,30),"纵向滑动当前进度条:"+ verticalValue + "%");GUI.Label (new Rect (10, 210, Screen.width, 30), "横向滑动当前进度条:" + horizontaValue + "%");}void Start () {}// Update is called once per framevoid Update () {}}

按键控制cube移动 旋转

using UnityEngine;using System.Collections;public class cube_move : MonoBehaviour {public int movespeed;// Use this for initializationvoid Start () {movespeed = 10;}// Update is called once per framevoid Update () {//键盘按下事件if (Input.GetKeyDown (KeyCode.W)) {transform.Translate(Vector3.forward * movespeed);}if (Input.GetKeyDown (KeyCode.S)) {transform.Translate(Vector3.forward * (-movespeed));}if (Input.GetKeyDown (KeyCode.D)) {transform.Translate(Vector3.right * movespeed);}if (Input.GetKeyDown (KeyCode.A)) {transform.Translate(Vector3.right * (-movespeed));}//up right forward 分别控制三个面的旋转if (Input.GetKeyDown (KeyCode.E)) {transform.Rotate (Vector3.up * movespeed);}if (Input.GetKeyDown (KeyCode.Q)) {transform.Rotate (Vector3.up * (-movespeed));}}}


0 0
原创粉丝点击