Unity场景构建
1、如何给场景添加小地图?
- Step1:在Texture中创建一个Render Texture,命名为MinimapCamera;
- Step2:在Hierarchy中创建一个新的Camera,命名为MinimapCamera。
 在Inspector中将Layer属性设置为Minimap,Culling Mask属性设置为只渲染Minimap层,将Target Texture属性设置为MinimapCamera;
- Step3:在Hierarchy中创建一个新的UI -> Raw Image,命名为MinimapImage,将MinimapCamera赋值给Raw Image的Texture属性。
- Step4:让相机跟随玩家移动,可以通过脚本实现。
 脚本代码如下:
// FollowMiniMapCamera.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowMiniMapCamera : MonoBehaviour
{
    public Transform player; // 主角的 Transform 组件
    public float offsetX; // 小地图相机与主角在 X 轴上的偏移量
    public float offsetY = 10; // 小地图相机与主角在 Y 轴上的偏移量
    public float offsetZ; // 小地图相机与主角在 Z 轴上的偏移量
    // Start is called before the first frame update
    void Start()
    {
    }
    // Update is called once per frame
    void Update()
    {
        // 将小地图相机的位置更新为主角的位置加上偏移量
        transform.position = new Vector3(player.position.x + offsetX, offsetY, player.position.z + offsetZ);
    }
}
2、如何添加街道、树木等环境元素?
在Unity Asset Store中搜索“street”、“road”等关键词,可以找到大量免费或付费的街道模型,选择合适的模型导入到项目中即可。
Small Town America - Streets - FREE | 3D | Unity Asset Store
 
                        
                        