码迷,mamicode.com
首页 > 编程语言 > 详细

Unity之2D游戏界面相机控制

时间:2015-04-30 21:53:55      阅读:1022      评论:0      收藏:0      [点我收藏+]

标签:

之前写的关于2D游戏界面相机的水平、竖直、以人为中心三种模式的相机控制,我写着写着,总感觉相机适配有点繁琐,而且适配得不怎么好,多平台的时候因为资源有限我也不知道有没有完全适配,今天给大家分享一下我今天写的一个2D游戏场景相机适配,感觉挺好的,有需要的可以用着试试看,接下来我贴上代码:

using UnityEngine;
using System.Collections;

public class CameraControl_2D : MonoBehaviour {

    // 默认屏幕大小
    float width = 854.0f;
    float height = 480.0f;

    // Use this for initialization
    void Awake()
    {
        
        // 屏幕适配
        float orthographicSize = this.GetComponent<Camera>().orthographicSize;
        print("aa:" + orthographicSize);
        orthographicSize *= (Screen.height / (float)Screen.width) / (height / width);
        print("bb:" + orthographicSize);
        this.GetComponent<Camera>().orthographicSize = orthographicSize;
    }

}


Unity之2D游戏界面相机控制

标签:

原文地址:http://blog.csdn.net/hongyouwei/article/details/45399021

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!