- Home /
Question by
Pipioca · Oct 07, 2017 at 10:51 AM ·
c#camerascripting problem
Placing a dynamic board in the exact Center of the Camera
Hi!
Good Morning,
I'm trying to make a dynamic board of cards for a game. The problem I have is that the board does not come centered when the size of the board varies. I've tried it every way but I can not find a way to make it work.
I create the board as follows:
public void CrearTableroCartas () {
int cont = 0;
for(int x=0; x<anchoAlto; x++){
for(int i=0; i<anchoAlto; i++){
float factor = 9.0f / anchoAlto;
Vector3 posicionTemp = new Vector3(x * factor, i * factor, 0);
GameObject cartaTemporal = Instantiate(carta, posicionTemp, Quaternion.Euler(new Vector3(0, 180, 0)));
cartaTemporal.transform.localScale *= factor;
cartaTemporal.transform.position = posicionTemp;
}
}
Attached two images of the problem. You can see that if the board has many cards, it focuses but if there are few the size is fine but they do not stay centered and lose a little.
Does anyone have any idea how to solve it?
Thank you very much in advance!
Greetings.
Comment
Answer by AshwinTheGammer · Oct 07, 2017 at 10:56 AM
Use this script just put the GameObject
var DyanmicBoard : GameObject;
function Start ()
{
FirePoint.transform.position = Camera.main.ScreenToWorldPoint( Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane) );
You can resize the board when you want.