## unity 3d项目 原

钟元大老爷

• 空间 收藏于2011-02-11

LookAtObj.js

var target : Transform;
var xSpeed = 250.0;
var ySpeed = 120.0;

var yMinLimit = 0;
var yMaxLimit = 80;
var offsetR:int = 90;
var initDis = 20;
var minDis = 3.0;
var maxDis = 20.0;
var mouseMode:int = 0;
var wheelSpeed = 5;
var offsetY:int  =1;
var offsetX:int  = 97;
var offsetZ:int  = 74;
static var x = 0.0;
static var y = 0.0;

static  var distance;

private var position;
private var rotation;

function Start () {
transform.position.x = -.2;
transform.position.y = .6;
transform.position.z = -4.3;
transform.Rotate(0,offsetR,0);
//transform.LookAt(target);

// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
/***拖拽角度**/
function Update () {
if (target) {
distance = Vector3.Distance(target.position,transform.position);
if(Input.GetMouseButton(mouseMode)){
x += Input.GetAxis("Mouse X") * xSpeed * 0.02;
y -= Input.GetAxis("Mouse Y") * ySpeed * 0.02;

y = ClampAngle(y, yMinLimit, yMaxLimit);
}

distance-= Input.GetAxis("Mouse ScrollWheel")*wheelSpeed;//获取鼠标中建响应
distance = Mathf.Clamp(distance,minDis,maxDis);//距离取最大值和最小值

rotation = Quaternion.Euler(y, x, 0);
position = rotation * Vector3(0.0, 0.0, -distance) + target.position;

transform.rotation = rotation;
transform.position = position;

}
}
/**处理角度*/
static function ClampAngle (angle : float, min : float, max : float) {
if (angle < -360)
angle += 360;
if (angle > 360)
angle -= 360;
return Mathf.Clamp (angle, min, max);
}

Controller.js

var  _carType:GameObject[];
var  _bodys:GameObject[]  =  [];
var _length :int;
var  defaultSkin:GUISkin;
var  luns:GameObject;
var textures: Texture2D[];
var lunTexture:Texture2D[];
private var  status = false;
private var  labels:Array ;

private var  state:int = 0;
function Start(){
status = true;
}
function  OnGUI(){
if(status){
labels = [];
_length = textures.length;
for(var i:int = 0; i<_length ;i++){
labels[i]  =  {"name":textures[i].name,"body":textures[i]};
}

GUI.skin  = defaultSkin;
GUI.Box(Rect(0,Screen.height -100,Screen.width,190),"");
GUI.Label(Rect(0,Screen.height - 100,180,20),"change  body's textures");
while( --_length >= 0){
createButton(180 + _length * 50,Screen.height - 100 ,labels[_length]["name"],labels[_length]["body"]);
}
GUI.Label(Rect(0,Screen.height - 70,180,20),"change  car's type");
if(GUI.Button(Rect(240, Screen.height - 70,50,25),"Change")){
closeAll();
if(state == 0) state = 1;
else         state = 0;

if(state  == 0){
_carType[0] .renderer.enabled = true;
luns.renderer.materials[1].mainTexture =  lunTexture[0];
luns.renderer.materials[2] .mainTexture=  lunTexture[1];
}else{
for(  var  j:int =1 ; j < _carType.length; j++){
_carType[j].renderer.enabled = true;
}
luns.renderer.materials[1] .mainTexture=  lunTexture[2];
luns.renderer.materials[2] .mainTexture=  lunTexture[3];
}
}
}else  return;

}
function  closeAll():void{
if(_carType != null){
for(  var  i:int =0 ; i < _carType.length; i++){
_carType[i].renderer.enabled = false;
}
}
}
function  createButton(x:int,y:int,_name_,_body_){
if(GUI.Button(Rect(x,y,50,25),_name_)){
doExecute(_name_,_body_);
}
}

function  doExecute(_command_:String,_body_){
for(var i:int =0 ; i < _bodys.length; i++){
_bodys[i].renderer.material.mainTexture = _body_;
}
}

### 钟元大老爷

wendy-jiaxin
2016/12/23
139
0
Unity 和腾讯游戏成立联合创新实验室：从技术创新探索游戏产品新模式和概念

2019年5月12日，Unity和腾讯游戏共同宣布成立联合创新实验室。双方将充分发挥各自深耕在游戏领域多年的技术优势，协同创新、共同探索未来游戏产品新模式和概念，致力于技术上的飞跃性突破，为...

CSDN资讯
05/12
0
0
Unity3D 游戏引擎之构建游戏框架与导出IOS项目（一）

Unity3D游戏引擎之构建游戏框架与导出IOS项目 雨松MOMO原创文章如转载，请注明：转载自雨松MOMO的博客原文地址:http://blog.csdn.net/xys289187120/article/details/6862563 首先先去Unity3D...

2012/03/09
897
0

csdn资讯
04/08
0
0
Unity3D - 图片资源导入的一些基础知识

qq_17758883
2018/04/11
0
0

CSS--列表

wytao1995

4
0
linux 命令-文本比较comm、diff、patch

7
0
QML教程

https://blog.csdn.net/qq_40194498/article/category/7580030 https://blog.csdn.net/LaineGates/article/details/50887765...

shzwork

5
0
HA Cluster之5

lhdzw

6
0

《玩转Redis》系列文章主要讲述Redis的基础及中高级应用，文章基于Redis5.0.4+。本文主要讲述Redis的数据结构String，《玩转Redis-Redis基础数据结构及核心命令》相关操作命令为方便对比...

zxiaofan666

11
0