I am developing a board game. My board is created dynamically using C# script like so
/// <summary>
/// Draws the board of the figure. Call the Load event of the form.
/// </summary>
public void DrawingBoard()
{
CubeDark.transform.localScale = new Vector3(3f,2f,3f);
CubeLight.transform.localScale = new Vector3(3f,2f,3f);
for(int i = 0; i < _boardSize; i++)
{
for(int j = 0; j < _boardSize; j++)
{
if((i+j)%2 == 0)
{
UnityEngine.Object.Instantiate(CubeDark,new Vector3(i*3,_boardHeight,j*3), Quaternion.identity);
}
else
{
UnityEngine.Object.Instantiate(CubeLight,new Vector3(i*3,_boardHeight,j*3), Quaternion.identity);
}
}
}
}
Screenshot:
What I want to do now is to scale the camera in order to put the board in the center of the screen ( no matter what size of screen ).
What I have tried so far is to attach the below script to my camera GameObject.
using UnityEngine;
using System.Collections;
public class PositionCamera : MonoBehaviour {
public float fWidth = 2.0f; // Desired width
void Start () {
float xFactor = Screen.width / 1024f;
float yFactor = Screen.height / 768f;
Camera.main.rect=new Rect(0,0,1,xFactor/yFactor);
}
}
But unfortunately, it didn't work. A part of the board still does not appear.
So here come my questions:
- How can i keep my board centered for different screen resolution and for different platforms ( android and standalone )?
- How can i make my game window resizable when building my unity project?
- For android platform, Why does only half of the screen show the game?
Thanks.
Aucun commentaire:
Enregistrer un commentaire