Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
man-in-the-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MIM
man-in-the-mirror
Commits
590da1cf
Commit
590da1cf
authored
May 12, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
발사모드/일반모드 전환 시 카메라가 플레이어의 머리 위치로 줌인/줌아웃 됨
parent
15bcb18e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
118 additions
and
29 deletions
+118
-29
Data.meta
Assets/Data.meta
+0
-8
Player.prefab
Assets/Prefabs/Player.prefab
+33
-1
SampleScene.unity
Assets/Scenes/SampleScene.unity
+4
-4
CameraController.cs
Assets/Scripts/CameraController.cs
+53
-5
Player.cs
Assets/Scripts/Player.cs
+21
-9
PlayerController.cs
Assets/Scripts/PlayerController.cs
+7
-2
No files found.
Assets/Data.meta
deleted
100644 → 0
View file @
15bcb18e
fileFormatVersion: 2
guid: f6226b2548447a54486acfc694a44e4d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
Assets/Prefabs/Player.prefab
View file @
590da1cf
%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
...
...
Assets/Scenes/SampleScene.unity
View file @
590da1cf
...
...
@@ -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.2
3911765
,
y
:
0.3696438
,
z
:
-0.09904577
,
w
:
0.89239913
}
m_LocalPosition
:
{
x
:
-
5
,
y
:
10
,
z
:
-5
}
m_LocalRotation
:
{
x
:
0.2
2350667
,
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
...
...
Assets/Scripts/CameraController.cs
View file @
590da1cf
...
...
@@ -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
();
}
}
}
Assets/Scripts/Player.cs
View file @
590da1cf
...
...
@@ -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
()
...
...
Assets/Scripts/PlayerController.cs
View file @
590da1cf
...
...
@@ -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
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment