- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
var wheelFL : Transform;
var wheelFR : Transform;
var wheelRL : Transform;
var wheelRR : Transform;
var oFL : Transform;
var oFR : Transform;
var rearWheel1 : WheelCollider;
var rearWheel2 : WheelCollider;
var frontWheel1 : WheelCollider;
var frontWheel2 : WheelCollider;
var steer_max = 20;
var motor_max = 70;
var brake_max = 150;
private var steer = 0;
private var forward = 0;
private var back = 0;
private var motor = 0;
private var brake = 0;
private var reverse = false;
private var speed = 0;
private var body;
public var mskin : GUISkin;
private var oldmovie = false;
function Start()
{
rigidbody.centerOfMass = Vector3(0, -0.57, 0);
}
function Update()
{
}
function changecolor(mcolor:Color)
{
for(i in GameObject.FindGameObjectsWithTag("carBody"))
for(j in i.renderer.materials)
if(j.shader.name=="Reflective/Specular")
j.SetColor("_Color",mcolor);
}
function FixedUpdate ()
{
speed = rigidbody.velocity.sqrMagnitude;
steer = Mathf.Clamp(Input.GetAxis("Horizontal"), -1, 1);
forward = Mathf.Clamp(Input.GetAxis("Vertical"), 0, 1);
back = -1 * Mathf.Clamp(Input.GetAxis("Vertical"), -1, 0);
if(speed == 0)
{
if(back > 0) { reverse = true; }
if(forward > 0) { reverse = false; }
}
if(reverse)
{
motor = -1 * back;
brake = forward;
}
else
{
motor = forward;
brake = back;
}
if(speed<500)
{
rearWheel1.motorTorque = motor_max * motor;
rearWheel2.motorTorque = motor_max * motor;
frontWheel1.motorTorque = motor_max * motor;
frontWheel2.motorTorque = motor_max * motor;
}
else
{
rearWheel1.motorTorque = 0;
rearWheel2.motorTorque = 0;
frontWheel1.motorTorque = 0;
frontWheel2.motorTorque = 0;
}
rearWheel1.brakeTorque = brake_max * brake;
rearWheel2.brakeTorque = brake_max * brake;
frontWheel1.brakeTorque = brake_max * brake;
frontWheel2.brakeTorque = brake_max * brake;
frontWheel1.steerAngle = steer_max * steer;
frontWheel2.steerAngle = steer_max * steer;
var mRotation : Quaternion;
mRotation=Quaternion.Euler( 0 ,20* steer, 0) * Quaternion.identity;
oFL.localRotation= mRotation;
oFR.localRotation= mRotation;
wheelFL.Rotate(frontWheel1.rpm * 6 * Time.deltaTime,0, 0 );
wheelFR.Rotate(frontWheel1.rpm * 6 * Time.deltaTime,0, 0 );
wheelRL.Rotate(frontWheel1.rpm * 6 * Time.deltaTime,0, 0 );
wheelRR.Rotate(frontWheel1.rpm * 6 * Time.deltaTime,0, 0 );
var hit : WheelHit;
//if the wheel touches the ground, adjust graphical wheel position to reflect springs
if(frontWheel1.GetGroundHit(hit))
wheelFL.localPosition.y-=Vector3.Dot(wheelFL.position-hit.point,transform.up)-frontWheel1.radius*0.14-0.15;
if(frontWheel2.GetGroundHit(hit))
wheelFR.localPosition.y-=Vector3.Dot(wheelFR.position-hit.point,transform.up)-frontWheel2.radius*0.14-0.15;
if(rearWheel1.GetGroundHit(hit))
wheelRL.localPosition.y-=Vector3.Dot(wheelRL.position-hit.point,transform.up)-rearWheel1.radius*0.14-0.15;
if(rearWheel2.GetGroundHit(hit)) {
wheelRR.localPosition.y-=Vector3.Dot(wheelRR.position-hit.point,transform.up)-rearWheel2.radius*0.14-0.15;
}
}
function OnGUI()
{
GUI.skin=mskin;
if(GUI.Button(Rect(10,10,70,30),"红"))
changecolor(Color.red);
if(GUI.Button(Rect(100,10,70,30),"白"))
changecolor(Color.white);
if(GUI.Button(Rect(200,10,70,30),"黑"))
changecolor(Color.black);
if(GUI.Button(Rect(300,10,70,30),"蓝"))
changecolor(Color.blue);
if(GUI.Button(Rect(400,10,70,30),"灰"))
changecolor(Color.grey);
if(GUI.Button(Rect(500,10,150,30),"旧电影效果"))
{
if(oldmovie==false)
{
GameObject.Find("Camera").GetComponent("ColorCorrectionEffect").enabled = true;
GameObject.Find("Camera").GetComponent("NoiseEffect").enabled = true;
oldmovie=true;
}
else
{
GameObject.Find("Camera").GetComponent("ColorCorrectionEffect").enabled = false;
GameObject.Find("Camera").GetComponent("NoiseEffect").enabled = false;
oldmovie=false;
}
}
}
转载出处:http://blog.csdn.net/Cancer05/archive/2010/01/26/5258657.aspx |
|