Скрипт почти дописан опытным путем)), но остается один вопрос: Как получить эти же значения формулой, что бы в будущем приближать-отдалять и ничего не сбивалось? Это значения когда камера доходит до границы TileMap cameraPos on bounds = x2.4 y2 (при orthographicSize = 5)
using UnityEngine;
public class CameraController : MonoBehaviour
{
Vector3 mousePos;
GameManager gameManager;
float boundX;
float boundY;
private void Start()
{
gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
boundX = gameManager.gameMapSize.x - 1;
boundY = gameManager.gameMapSize.y - 1;
}
void Update()
{
if (Input.GetMouseButton(0))
{
mousePos.x -= Input.GetAxis("Mouse X") / 2;
if (mousePos.x > 2.4f)
{
mousePos.x += Input.GetAxis("Mouse X") / 2;
}
mousePos.y -= Input.GetAxis("Mouse Y") / 2;
if (mousePos.y > 2f)
{
mousePos.y += Input.GetAxis("Mouse Y") / 2;
}
mousePos.z = transform.position.z;
Debug.Log(mousePos.x + " " + mousePos.y);
Camera.main.transform.position = mousePos;
}
}
void ValidPos()
{
Camera cam = Camera.main;
float height = 2f * cam.orthographicSize;
float width = height * cam.aspect;
//Height: 10
//Width: 21.21
//tilemapSize = x26, y14
//cameraPos on bounds = x2.4 y2
}
}