포켓몬2D 블루 페어리 블루 만들 때 만든건데...카메라 시점이 따라 움직임 2D에서...
/*! CameraFollow2D.cs
* X-UniTMX: A tiled map editor file importer for Unity3d
* https://bitbucket.org/Chaoseiro/x-unitmx
*
* Copyright 2013-2014 Guilherme "Chaoseiro" Maia
* 2014 Mario Madureira Fontes
*/
using UnityEngine;
using System.Collections;
namespace X_UniTMX.Internal
{
public class CameraFolow2D : MonoBehaviour
{
public float smoothMovement = 3.0f;
public Vector2 relativeDistance = Vector2.zero;
public string tagToFollow = "Player";
private GameObject playerRefence = null;
private Transform myTransform;
private void Awake()
{
myTransform = transform;
}
Vector3 GetPlayerPosition()
{
return new Vector3(playerRefence.transform.position.x + relativeDistance.x, // get X from player
playerRefence.transform.position.y + relativeDistance.y, // get Yfrom player
myTransform.position.z); // get X from camera
}
void TryToFindPlayer()
{
// Obtem a instancia do objeto do jogador
playerRefence = GameObject.FindWithTag(tagToFollow) as GameObject;
if (playerRefence != null)
{
// Set current position camera to player
myTransform.position = GetPlayerPosition();
}
}
void Start()
{
TryToFindPlayer();
}
void Update()
{
if (playerRefence == null)
{
TryToFindPlayer();
if (playerRefence == null)
{
return;
}
}
Vector3 newPosition = GetPlayerPosition();
// Interpolate camera position to player
myTransform.position = Vector3.Lerp(myTransform.position, newPosition, smoothMovement * Time.deltaTime);
}
}
}
/*! CameraController.cs
* X-UniTMX: A tiled map editor file importer for Unity3d
* https://bitbucket.org/Chaoseiro/x-unitmx
*
* Copyright 2013-2014 Guilherme "Chaoseiro" Maia
* 2014 Mario Madureira Fontes
*/
using UnityEngine;
using System.Collections;
namespace X_UniTMX.Internal
{
public class CameraController : MonoBehaviour
{
public float PixelsPerUnit = 32.0f;
public Vector3 CamPos = Vector3.zero;
float ortographicSize;
public float Scale = 1.0f;
float scrollWheel;
// Use this for initialization
void Start()
{
CamPos = Camera.main.transform.position;
ortographicSize = Camera.main.orthographicSize;
Scale = 1;//Screen.height / 320.0f;
}
// Update is called once per frame
void Update()
{
ortographicSize = Screen.height / 2.0f / PixelsPerUnit / Scale;
if (Input.GetKey(KeyCode.W))
{
CamPos.y += 1 / PixelsPerUnit * 10;
}
if (Input.GetKey(KeyCode.S))
{
CamPos.y -= 1 / PixelsPerUnit * 10;
}
if (Input.GetKey(KeyCode.A))
{
CamPos.x -= 1 / PixelsPerUnit * 10;
}
if (Input.GetKey(KeyCode.D))
{
CamPos.x += 1 / PixelsPerUnit * 10;
}
scrollWheel = Input.GetAxis("Mouse ScrollWheel");
if (scrollWheel != 0)
{
Scale += scrollWheel;
if (Scale < 0.1f)
Scale = 0.1f;
}
Camera.main.transform.position = CamPos;
Camera.main.orthographicSize = ortographicSize;
}
void OnGUI()
{
GUI.Label(new Rect(0.95f * Screen.width, 0.01f * Screen.height, 0.1f * Screen.width, 0.1f * Screen.height), "Scale:");
Scale = GUI.VerticalSlider(new Rect(0.95f * Screen.width, 0.05f * Screen.height, 0.01f * Screen.width, 0.1f * Screen.height), Scale, 10.0f, 0.1f);
}
}
}
잘짰네
Copyright 2013-2014 Guilherme "Chaoseiro" Maia X-UniTMX 네가 짠건지 활용한건지 모르겠음
2년전이 기억 안남
2014년 12월 부터 1월까지
너무 오래되서 기억이 안나서 오랜만에 찾았음.
이 시람이 만든거는 Base 기본인데, 거기다가 가미했는지 아니면... 이걸 기반으로 만든게 있어서 참고하려고 가져왔음.
이 분이 만든거는 Base 기본인데, 거기다가 추가로 네가 코드를 적었는지 이걸 기반으로 2차 가공한게 있는데, 그 소스를 날려서 2015년 2월 17일에...
원본
https://bitbucket.org/Chaoseiro/x-unitmx/src/Unity2D/Assets/X-UniTMX%20Examples/GameScene-TopView/Scripts/Camera/CameraFolow2D.cs
Screen.height / 2.0f / PixelsPerUnit 는 미리 계산해서 상수로 빼놓지 업데이트 분기마다 나눗셈을 3번이나 하고 있네ㅋㅋ
형 이거 재활용하려면 어떻게 출처 표기해야할까요. 활용할때 라이센스 활용하는게 어렵더라...
백업소스에서 가져온거라서, 나도 2014년 ~ 2015년 기억이 안남