Commit 590da1cf authored by 18손재민's avatar 18손재민

발사모드/일반모드 전환 시 카메라가 플레이어의 머리 위치로 줌인/줌아웃 됨

parent 15bcb18e
fileFormatVersion: 2
guid: f6226b2548447a54486acfc694a44e4d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &5325636473742838123
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 995136353672390943}
m_Layer: 0
m_Name: Head
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &995136353672390943
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5325636473742838123}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0.75, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 8862060874303168219}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &8862060874303168220
GameObject:
m_ObjectHideFlags: 0
......@@ -32,7 +62,8 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Children:
- {fileID: 995136353672390943}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
......@@ -107,6 +138,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ceb8a784e77658342887555993532b12, type: 3}
m_Name:
m_EditorClassIdentifier:
head: {fileID: 5325636473742838123}
--- !u!195 &8862060874303168218
NavMeshAgent:
m_ObjectHideFlags: 0
......
......@@ -233,7 +233,7 @@ Camera:
near clip plane: 0.3
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic: 0
orthographic size: 5
m_Depth: -1
m_CullingMask:
......@@ -257,13 +257,13 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 534669902}
m_LocalRotation: {x: 0.23911765, y: 0.3696438, z: -0.09904577, w: 0.89239913}
m_LocalPosition: {x: -5, y: 10, z: -5}
m_LocalRotation: {x: 0.22350667, y: 0.3713161, z: -0.09257949, w: 0.8964364}
m_LocalPosition: {x: -12, y: 10, z: -12}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 30, y: 45, z: 0}
m_LocalEulerAnglesHint: {x: 28, y: 45, z: 0}
--- !u!114 &534669906
MonoBehaviour:
m_ObjectHideFlags: 0
......
......@@ -6,7 +6,11 @@ public class CameraController : MonoBehaviour
{
Vector3 dragOrigin;
public float dragSpeed;
Vector3 previousPos;
bool isZooming = false;
/// <summary>
/// Move camera.
/// </summary>
void CameraMove()
{
float horizontalInput = Input.GetAxis("Horizontal");
......@@ -14,9 +18,11 @@ public class CameraController : MonoBehaviour
transform.position += new Vector3(verticalInput + horizontalInput, 0, verticalInput - horizontalInput);
}
/// <summary>
/// Rotate camera with mouse right click.
/// </summary>
void CameraDrag()
{
if (Input.GetMouseButtonDown(1))
{
dragOrigin = Input.mousePosition;
......@@ -31,9 +37,48 @@ public class CameraController : MonoBehaviour
float dif = Camera.main.ScreenToViewportPoint(Input.mousePosition - dragOrigin).x * dragSpeed;
transform.position = new Vector3(Mathf.Cos(deg + dif) * dis, transform.position.y, Mathf.Sin(deg + dif) * dis);
transform.LookAt(new Vector3(0, 0, 0));
transform.LookAt(new Vector3(0, 1, 0));
dragOrigin = Input.mousePosition;
}
/// <summary>
/// Zoom in at player.
/// </summary>
/// <param name="player">Player to be zoomed in.</param>
/// <returns></returns>
public IEnumerator ZoomInAtPlayer(Player player)
{
float startTime = Time.time;
Vector3 posDiff = (player.head.transform.position - transform.position) / 50;
Vector3 angleDiff = (new Vector3(0, transform.eulerAngles.y, 0) - transform.eulerAngles) / 50;
previousPos = transform.position;
for (int i = 0; i < 50; i++)
{
yield return null;
Debug.Log(transform.position);
transform.position += posDiff;
transform.eulerAngles += angleDiff;
}
transform.position = player.head.transform.position;
}
/// <summary>
/// Zoom out from player.
/// </summary>
/// <returns></returns>
public IEnumerator ZoomOutFromPlayer()
{
float startTime = Time.time;
Vector3 posDiff = (previousPos - transform.position) / 50;
Vector3 angleDiff = (new Vector3(30, transform.eulerAngles.y, transform.eulerAngles.z) - transform.eulerAngles) / 50;
for (int i = 0; i < 50; i++)
{
yield return null;
Debug.Log(transform.position);
transform.position += posDiff;
transform.eulerAngles += angleDiff;
}
transform.position = previousPos;
PlayerController.inst.isPlayerShooting = false;
}
// Start is called before the first frame update
void Start()
......@@ -45,9 +90,12 @@ public class CameraController : MonoBehaviour
// Update is called once per frame
void Update()
{
if (!PlayerController.inst.isPlayerShooting)
{
CameraMove();
CameraDrag();
}
}
}
......@@ -6,6 +6,7 @@ using UnityEngine.AI;
public class Player : MonoBehaviour
{
Coroutine playerArrivalCheck;
public GameObject head;
public IEnumerator SetCurrentPlayer()
{
......@@ -19,6 +20,10 @@ public class Player : MonoBehaviour
GetComponent<NavMeshObstacle>().enabled = true;
PlayerController.inst.currentPlayer = null;
}
/// <summary>
/// Move player to the destination.
/// </summary>
/// <param name="destination">Destination of the player.</param>
public void MovePlayer(Vector3 destination)
{
NavMeshAgent agent = GetComponent<NavMeshAgent>();
......@@ -33,6 +38,11 @@ public class Player : MonoBehaviour
else
Debug.Log("Destination is not reachable.");
}
/// <summary>
/// Check if player is arrived at the destination.
/// </summary>
/// <param name="destination">Destination of the player.</param>
/// <returns></returns>
IEnumerator CheckIfPlayerArrived(Vector3 destination)
{
while (Mathf.Abs(transform.position.x - destination.x) > 0.01f || Mathf.Abs(transform.position.z - destination.z) > 0.01f)
......@@ -42,20 +52,22 @@ public class Player : MonoBehaviour
transform.position = new Vector3(destination.x, transform.position.y, destination.z);
PlayerController.inst.isPlayerMoving = false;
}
public IEnumerator ZoomInAtPlayer(float startTime)
public IEnumerator CountPlayerClick(float startTime)
{
Ray mouseRay;
RaycastHit hit;
while(Time.time - startTime <= 2)
float time = Time.time;
float endTime = startTime + 2;
while(time <= endTime)
{
yield return null;
mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Physics.Raycast(mouseRay, out hit);
if (!hit.collider.gameObject.tag.Equals("Player"))
time = Time.time;
if (!Input.GetMouseButton(0))
break;
}
if (Time.time - startTime <= 2) ;
else Debug.Log("asdf");
if (time > endTime)
{
PlayerController.inst.isPlayerShooting = true;
StartCoroutine(Camera.main.GetComponent<CameraController>().ZoomInAtPlayer(this));
}
}
// Start is called before the first frame update
void Start()
......
......@@ -8,6 +8,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
{
public Player currentPlayer;
public bool isPlayerMoving;
public bool isPlayerShooting;
private Vector2Int prePos;
public Vector2Int MapPos
{
......@@ -38,7 +39,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
prePos = MapPos;
}
if (Input.GetMouseButtonDown(0) && !isPlayerMoving)
if (Input.GetMouseButtonDown(0) && !isPlayerMoving && !isPlayerShooting)
{
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
......@@ -48,7 +49,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
currentPlayer.ResetCurrentPlayer();
currentPlayer = hit.transform.gameObject.GetComponent<Player>();
StartCoroutine(currentPlayer.SetCurrentPlayer());
StartCoroutine(currentPlayer.ZoomInAtPlayer(Time.time));
StartCoroutine(currentPlayer.CountPlayerClick(Time.time));
Debug.Log(hit.collider.gameObject.tag);
}
else if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor"))
......@@ -63,5 +64,9 @@ public class PlayerController : SingletonBehaviour<PlayerController>
currentPlayer.ResetCurrentPlayer();
}
}
else if (Input.GetMouseButtonDown(1) && isPlayerShooting)
{
StartCoroutine(Camera.main.GetComponent<CameraController>().ZoomOutFromPlayer());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment