资源简介
这是一个利用unity3D开发的汽车小游戏(包含游戏源代码)
代码片段和文件信息
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation
/// To make an FPS style character:
/// - Create a capsule.
/// - Add a rigid body to the capsule
/// - Add the MouseLook script to the capsule.
/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSWalker script to the capsule
/// - Create a camera. Make the camera a child of the capsule. Reset it‘s transform.
/// - Add a MouseLook script to the camera.
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu(“Camera-Control/Mouse Look“)]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0 MouseX = 1 MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationX = 0F;
float rotationY = 0F;
Quaternion originalRotation;
void Update ()
{
if (axes == RotationAxes.MouseXAndY)
{
// Read the mouse input axis
rotationX += Input.GetAxis(“Mouse X“) * sensitivityX;
rotationY += Input.GetAxis(“Mouse Y“) * sensitivityY;
rotationX = ClampAngle (rotationX minimumX maximumX);
rotationY = ClampAngle (rotationY minimumY maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
rotationX += Input.GetAxis(“Mouse X“) * sensitivityX;
rotationX = ClampAngle (rotationX minimumX maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
else
{
rotationY += Input.GetAxis(“Mouse Y“) * sensitivityY;
rotationY = ClampAngle (rotationY minimumY maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY Vector3.left);
transform.localRotation = originalRotation * yQuaternion;
}
}
void Start ()
{
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
}
public static float ClampAngle (float angle float min float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle min max);
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6148 2009-08-06 16:17 Unity3D 一个汽车竞技的源码\CarTutorialProject\.DS_Store
文件 12612 2009-08-09 14:26 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\.mayaSwatches\Road_Texture.psd.Composite.swatch
文件 197120 2009-08-05 20:04 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Car\Car_Model.mb
文件 3801 2009-08-09 18:03 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Car\Materials\Car_Material.mat
文件 494 2009-06-05 12:46 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Car\Shaders\ConstantColorUnderla
文件 2027997 2009-06-02 20:53 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Car\Textures\Car_Texture.psd
文件 3748 2009-08-09 14:17 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Track\Materials\Road_Material.mat
文件 21793873 2009-08-02 02:24 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Track\Textures\Road_Texture.psd
文件 126640 2009-08-09 19:50 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Artwork\Track\Track.mb
文件 6413 2009-08-11 15:11 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\sc
文件 3534 2009-08-11 15:11 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\sc
文件 2469 2009-08-09 19:49 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\sc
文件 357 2009-08-09 19:49 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\sc
文件 266910 2009-08-01 17:12 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Sounds\Car\CarEngine_Sound.aif
文件 2705 2009-01-19 08:47 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Camera sc
文件 1046 2009-01-19 08:47 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Camera sc
文件 1873 2009-01-19 08:47 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Camera sc
文件 591 2009-01-19 08:47 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Camera sc
文件 4700 2008-07-02 04:59 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Blue sky.mat
文件 80374 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Back.jpg
文件 306 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Down.jpg
文件 98168 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Front.jpg
文件 88680 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Left.jpg
文件 82454 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Right.jpg
文件 97213 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Bluesky Up.jpg
文件 50779 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Sunset Back.jpg
文件 306 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Sunset Down.jpg
文件 65211 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Sunset Front.jpg
文件 57298 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Sunset Left.jpg
文件 51557 2007-10-07 15:01 Unity3D 一个汽车竞技的源码\CarTutorialProject\Assets\Standard Assets\Skyboxes\Source Images\Sunset Right.jpg
............此处省略434个文件信息
- 上一篇:x86:从实模式到保护模式
- 下一篇:linear optimal control
评论
共有 条评论