您的位置:首页 > 移动开发 > Unity3D

js操作unity模型旋转

2020-01-11 16:11 281 查看
#pragma strict

function Start () {

}

var run =0;
 var isOn:boolean;
 var RotateSpeed = 1000;  

function Update () {
   if (Input.touchCount == 1)   
        {  
        if(isOn == true){
        isOn=false;
        }  else{
        isOn=true;
        }
              //One finger touch does orbit  
//  
//                touch = Input.GetTouch(0);  
//  
//                x += touch.deltaPosition.x * xSpeed * 0.02;  
//  
//                y -= touch.deltaPosition.y * ySpeed * 0.02;  
  
        }  
          if(isOn == true){
  transform.Rotate(Vector3.up * Time.deltaTime * (-RotateSpeed));  
  }
    
}

function OnGUI()
{
//开关按钮,使用了三目运算符来控制显示on或者off
if(GUI.Button(Rect(0,0,200,40),(isOn)?"on":"off"))
{
//用三目运算符控制布尔类型开关变量值
if(isOn==true){
isOn=false;
}else{
isOn=true;
}

}


if(isOn)
{
//其他按钮的代码
}
}

转载于:https://my.oschina.net/jesusslim/blog/415558

  • 点赞
  • 收藏
  • 分享
  • 文章举报
站内首发文章 chuqian0842 发布了0 篇原创文章 · 获赞 0 · 访问量 1022 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: