功能实现:
1.创建一个GUITexture : create-> GUITexure;
此时可以通过修改component 栏中的选项,改变gui的texture等;
这样建立的GUITexture从属于整个屏幕平面,作为一个新的物体出现,他的位置不受camera的位置的影响,就是说,不管camera移动到哪里,这个GUI始终在你设定的位置;
2. 将GUIslider.js附加到GUITexture上;
maincamera作为其参数,应该将camera指定到上面;
------------------------------------------------------------------------------------------------------
----------------------------------华丽丽的分割线-----------------------------------------------------
代码 GUISlider.js
-----------------------------------------------------------------------------------------------------
var mainCamera:Camera;//将你自己的camera赋值到这个camera上面
var customButton : GUIStyle;// 为新出现的GUI设置Style
private var newPosition:Vector3;// GUI移动后新的位置
private var MouseUp: boolean;//显示Mouse是够是Up状态
private var getPosition : int = 0;//得到鼠标离开GUI的帧数
private var subGuiShowUp : int = 0;//统计帧数,控制subGUI出现
function Update () {
if(MouseUp){
if(getPosition < 12)
{
newPosition.x = mainCamera.ScreenToViewportPoint(Input.mousePosition).x;
getPosition +=1;
}
if(Mathf.Abs(transform.position.x - newPosition.x) > 0.00001){
transform.position.x += (newPosition.x - transform.position.x)*Time.deltaTime*6;
}
}
}
function OnMouseDrag(){
MouseUp = false;
subGuiShowUp +=1;
getPosition = 13;
transform.position.x += (mainCamera.ScreenToViewportPoint(Input.mousePosition).x - transform.position.x)*Time.deltaTime*10;
}
function OnMouseUp(){
print(transform.position.x);
MouseUp = true;
getPosition = 0;
//subGuiShowUp = 25;
}
function OnGUI(){
if(MouseUp){
if(subGuiShowUp < 12){
GUI.Button (Rect (5,5,100,100), "Hello World", customButton);
}
}
}
function OnMouseDown(){
subGuiShowUp = 0;
}
----------------------------------------------------------------------------------------------