纳金网

标题: 一个动态改变模型大小、方向的例子 [打印本页]

作者: star-小虎    时间: 2013-10-15 15:58
标题: 一个动态改变模型大小、方向的例子
public var mySkin:GUISkin;
var windowRect = Rect (0, 20, 200 ,150);
var SliderScaleValue:float = 0.0;
var SliderXValue:float = 0.0;
var SliderYValue:float = 0.0;
var SliderZValue:float = 0.0;
var SliderWindowRect = Rect(80,200,200,150);
var mCube:GameObject;
var xRotation:float;
var yRotation:float;
var zRotation:float;

function Start(){
     mCube = GameObject.Find("Cube");
     //print(mCube.transform.lossyScale + " -- " + mCube.transform.localScale);
     SliderScaleValue = mCube.transform.localScale.x;
}

function Update () {

}

function OnGUI () {
     GUI.skin = mySkin;
     SliderWindowRect = GUI.Window(1,SliderWindowRect,CreateWindow,"位置属性");
}

function CreateWindow(windowID : int){
     GUI.skin = mySkin;
     GUI.Label(Rect(10,20,50,20),"缩放");
     SliderScaleValue = GUI.HorizontalSlider (Rect(60,25,120,20),SliderScaleValue,0,500);
     //设置汽车的scale
     mCube.transform.localScale = Vector3(SliderScaleValue,SliderScaleValue,SliderScaleValue);

     GUI.Label(Rect(10,50,50,20),"旋转X");
     SliderXValue = GUI.HorizontalSlider (Rect(60,55,120,20),SliderXValue,0,360);
     //设置汽车的xRotation
     if(xRotation != SliderXValue){
           mCube.transform.rotation = Quaternion.Euler(SliderXValue,yRotation,zRotation);
           xRotation = SliderXValue;
     }


     GUI.Label(Rect(10,80,50,20),"旋转Y");
     SliderYValue = GUI.HorizontalSlider (Rect(60,85,120,20),SliderYValue,0,360);
     //设置汽车的yRotation
     if(yRotation != SliderYValue){
           mCube.transform.rotation = Quaternion.Euler(xRotation,SliderYValue,zRotation);;
           yRotation = SliderYValue;
     }

     GUI.Label(Rect(10,110,50,20),"旋转Z");
     SliderZValue = GUI.HorizontalSlider (Rect(60,115,120,20),SliderZValue,0,360);
     //设置汽车的zRotation
     if(zRotation != SliderZValue){
           mCube.transform.rotation = Quaternion.Euler(xRotation,yRotation,SliderZValue);;
           zRotation = SliderZValue;
     }

      GUI.DragWindow (Rect (0,0,10000,10000));
}


作者: nts    时间: 2013-10-16 09:54
没太看懂啊
作者: 小海豚    时间: 2013-10-29 17:58
不懂程序。。。编程




欢迎光临 纳金网 (http://old.narkii.com/club/) Powered by Discuz! X2.5