找回密码
 立即注册
楼主: 辣条

[渲染] Unity3D 一个动态改变模型大小、方向的例子

[复制链接]
发表于 2012-8-12 22:30 | 显示全部楼层 |阅读模式

先在场景内放置一个cube,设置一个guiskin,并附上中文字体。

-----------------------------------------------------------------------------------------------------------------
[code=javascript]
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));
}

[/code]
------------------------------------------------------------------------------------------------------

将上述代码保存为js,赋给cube就ok了

发表于 2013-4-22 19:58 | 显示全部楼层
第一行的代码好像没有用呀
发表于 2017-2-11 17:18 | 显示全部楼层
很不错
发表于 2017-2-11 16:43 | 显示全部楼层
好帖就是要顶
发表于 2017-2-11 17:07 | 显示全部楼层
真心顶
发表于 2017-2-11 17:19 | 显示全部楼层
难得一见的好帖
发表于 2017-2-11 17:13 | 显示全部楼层
说的非常好
发表于 2017-2-15 16:36 | 显示全部楼层
楼主是超人
发表于 2017-2-15 16:45 | 显示全部楼层
真心顶
发表于 2017-2-15 17:00 | 显示全部楼层
难得一见的好帖
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-11-22 01:42 , Processed in 0.129738 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表