- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
精短的一篇关于unity3d游戏中制作小地图效果的教程,推荐学习!没有源代码!
After starting your Unity project:
1. Select GameObject -> Create Other -> Camera, rename it as you like it
2. Select Assets -> Create -> Javas cript, rename it to "OrbitCam" or something similar ("Minimaps cript", etc.), edit it
3. Paste the following code:
javas cript code:var target : Transform;
var damping = 6.0;
var smooth = true;function LateUpdate () {
if (target) {
if (smooth)
{
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position -transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation,Time.deltaTime * damping);
}
else
{
// Just lookat
transform.LookAt(target);
}
transform.position.y = target.position.y + 90;
transform.position.x = target.position.x;
transform.position.z = target.position.z;
}
}
function Start () {
// Make the rigid body not change rotation
if (rigidbody)
rigidbody.freezeRotation = true;
}
4. Click the minimap camera you created earlier, then without clicking the s cript, drag the s cript onto the camera name
5. Still having the minimap camera on, drag the target of the minimap (the character, car, whatever) onto the field Target
All is set. Remember that the Depth of the minimap camera should be above the Depth value of the Main Camera, or the minimap itself will be hidden behind the Main Camera view! Very important!
An example of minimap camera properties set:
Projection property can be set as either Perspective or Othographic, with Field of View also customised to your needs.
Normalized View Port Rect properties can be set as following:
X: 0.04 (0.54 for the second minimap if you use the splitscreen multiplayer))
Y: 0.04 (0.54 for the second minimap)
X and Y properties specify the position of the minimap on the screen.
W: 0.2
H: 0.2
W (width) and H (height) properties specify the size of the minimap. 0.2 means 20%. You can set them as you wish.
And that's pretty everything you need to do to get a simple minimap. Remember it's a method very little optimised - better would be creating minimap itself (using a texture |
|