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
6f6cde67
Commit
6f6cde67
authored
Apr 07, 2019
by
18손재민
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
원하는 플레이어만 선택해서 이동가능
parent
0cb1a22a
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
18 deletions
+87
-18
Player.prefab
Assets/Prefabs/Player.prefab
+19
-2
SampleScene.unity
Assets/Scenes/SampleScene.unity
+11
-0
Map.cs
Assets/Scripts/Map/Map.cs
+17
-1
MapManager.cs
Assets/Scripts/MapManager.cs
+1
-1
Player.cs
Assets/Scripts/Player.cs
+30
-6
PlayerController.cs
Assets/Scripts/PlayerController.cs
+9
-8
No files found.
Assets/Prefabs/Player.prefab
View file @
6f6cde67
...
...
@@ -14,6 +14,7 @@ GameObject:
-
component
:
{
fileID
:
8862060874303168222
}
-
component
:
{
fileID
:
857076055737488221
}
-
component
:
{
fileID
:
8862060874303168218
}
-
component
:
{
fileID
:
5785432140392015245
}
m_Layer
:
8
m_Name
:
Player
m_TagString
:
Player
...
...
@@ -29,7 +30,7 @@ Transform:
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
8862060874303168220
}
m_LocalRotation
:
{
x
:
0
,
y
:
0
,
z
:
0
,
w
:
1
}
m_LocalPosition
:
{
x
:
0
,
y
:
1.5
,
z
:
3.18
}
m_LocalPosition
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_LocalScale
:
{
x
:
1
,
y
:
1
,
z
:
1
}
m_Children
:
[]
m_Father
:
{
fileID
:
0
}
...
...
@@ -113,7 +114,7 @@ NavMeshAgent:
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
8862060874303168220
}
m_Enabled
:
1
m_Enabled
:
0
m_AgentTypeID
:
0
m_Radius
:
0.5
m_Speed
:
5
...
...
@@ -128,3 +129,19 @@ NavMeshAgent:
m_BaseOffset
:
1
m_WalkableMask
:
4294967295
m_ObstacleAvoidanceType
:
4
---
!u!208
&5785432140392015245
NavMeshObstacle
:
m_ObjectHideFlags
:
0
m_CorrespondingSourceObject
:
{
fileID
:
0
}
m_PrefabInstance
:
{
fileID
:
0
}
m_PrefabAsset
:
{
fileID
:
0
}
m_GameObject
:
{
fileID
:
8862060874303168220
}
m_Enabled
:
1
serializedVersion
:
3
m_Shape
:
1
m_Extents
:
{
x
:
0.5
,
y
:
1
,
z
:
0.5
}
m_MoveThreshold
:
0.1
m_Carve
:
1
m_CarveOnlyStationary
:
0
m_Center
:
{
x
:
0
,
y
:
0
,
z
:
0
}
m_TimeToStationary
:
0.5
Assets/Scenes/SampleScene.unity
View file @
6f6cde67
...
...
@@ -490,6 +490,11 @@ PrefabInstance:
propertyPath
:
m_LocalEulerAnglesHint.z
value
:
0
objectReference
:
{
fileID
:
0
}
-
target
:
{
fileID
:
1444571407667829093
,
guid
:
0b18400fb62a12d4e9cb5fbb8ecbb53f
,
type
:
3
}
propertyPath
:
m_LocalPosition.z
value
:
0
objectReference
:
{
fileID
:
0
}
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
0b18400fb62a12d4e9cb5fbb8ecbb53f
,
type
:
3
}
---
!u!1001
&5089720519379341084
...
...
@@ -633,6 +638,12 @@ PrefabInstance:
propertyPath
:
surface
value
:
objectReference
:
{
fileID
:
2102809461
}
-
target
:
{
fileID
:
3268100033343711389
,
guid
:
11285456de5f1854d947bea83275646f
,
type
:
3
}
propertyPath
:
stage.Array.data[0]
value
:
objectReference
:
{
fileID
:
2597539376576235671
,
guid
:
bec0ce48aa2c7d14abcf504346360066
,
type
:
3
}
m_RemovedComponents
:
[]
m_SourcePrefab
:
{
fileID
:
100100000
,
guid
:
11285456de5f1854d947bea83275646f
,
type
:
3
}
---
!u!1001
&7277015660625800392
...
...
Assets/Scripts/Map/Map.cs
View file @
6f6cde67
...
...
@@ -199,6 +199,22 @@ public class Map : MonoBehaviour
Debug
.
Log
(
"Wall doesn't exists between : "
+
floor1
.
mapPos
+
", "
+
floor2
.
mapPos
);
}
private
void
LoadObjects
()
{
floorGrid
=
new
Dictionary
<
Vector2Int
,
Floor
>();
wallGrid
=
new
Dictionary
<
Vector2
,
Wall
>();
for
(
int
i
=
0
;
i
<
floors
.
transform
.
childCount
;
i
++)
{
Floor
floor
=
floors
.
transform
.
GetChild
(
i
).
GetComponent
<
Floor
>();
floorGrid
.
Add
(
floor
.
mapPos
,
floor
);
}
for
(
int
i
=
0
;
i
<
walls
.
transform
.
childCount
;
i
++)
{
Wall
wall
=
walls
.
transform
.
GetChild
(
i
).
GetComponent
<
Wall
>();
wallGrid
.
Add
(
wall
.
mapPos
,
wall
);
}
}
public
void
InitiateMap
()
{
floorGrid
=
new
Dictionary
<
Vector2Int
,
Floor
>();
...
...
@@ -208,7 +224,7 @@ public class Map : MonoBehaviour
private
void
Awake
()
{
LoadObjects
();
}
// Start is called before the first frame update
...
...
Assets/Scripts/MapManager.cs
View file @
6f6cde67
...
...
@@ -23,7 +23,7 @@ public class MapManager : SingletonBehaviour<MapManager>
currentMap
.
transform
.
position
=
new
Vector3
(
0
,
0
,
0
);
surface
.
BuildNavMesh
();
for
(
int
i
=
0
;
i
<
currentMap
.
startFloors
.
Count
;
i
++)
players
.
Add
(
Instantiate
(
player
,
currentMap
.
startFloors
[
i
].
transform
.
position
+
new
Vector3
(
0
,
1.5f
,
0
),
Quaternion
.
identity
));
players
.
Add
(
Instantiate
(
player
,
currentMap
.
startFloors
[
i
].
transform
.
position
+
new
Vector3
(
0
,
1.
1
5f
,
0
),
Quaternion
.
identity
));
}
public
IEnumerator
Rebaker
()
{
...
...
Assets/Scripts/Player.cs
View file @
6f6cde67
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
using
UnityEngine.AI
;
public
class
Player
:
MonoBehaviour
{
public
void
SetCurrentPlayer
()
Coroutine
playerArivalCheck
;
public
IEnumerator
SetCurrentPlayer
()
{
transform
.
localScale
=
new
Vector3
(
1
,
2
,
1
);
GetComponent
<
NavMeshObstacle
>().
enabled
=
false
;
yield
return
null
;
GetComponent
<
NavMeshAgent
>().
enabled
=
true
;
}
public
void
ResetCurrentPlayer
()
{
transform
.
localScale
=
new
Vector3
(
1
,
1
,
1
);
GetComponent
<
NavMeshAgent
>().
enabled
=
false
;
GetComponent
<
NavMeshObstacle
>().
enabled
=
true
;
PlayerController
.
inst
.
currentPlayer
=
null
;
}
public
void
MovePlayer
()
public
void
MovePlayer
(
Vector3
destination
)
{
NavMeshAgent
agent
=
GetComponent
<
NavMeshAgent
>();
NavMeshPath
path
=
new
NavMeshPath
();
if
(
playerArivalCheck
!=
null
)
StopCoroutine
(
playerArivalCheck
);
playerArivalCheck
=
StartCoroutine
(
CheckIfPlayerArrived
(
destination
));
agent
.
CalculatePath
(
destination
,
path
);
if
(
path
.
status
==
NavMeshPathStatus
.
PathComplete
)
GetComponent
<
NavMeshAgent
>().
SetDestination
(
destination
);
else
Debug
.
Log
(
"Destination is not reachable."
);
}
IEnumerator
CheckIfPlayerArrived
(
Vector3
destination
)
{
while
(
transform
.
position
.
x
!=
destination
.
x
||
transform
.
position
.
z
!=
destination
.
z
)
{
yield
return
null
;
PlayerController
.
inst
.
isPlayerMoving
=
true
;
}
PlayerController
.
inst
.
isPlayerMoving
=
false
;
}
// Start is called before the first frame update
void
Start
()
...
...
Assets/Scripts/PlayerController.cs
View file @
6f6cde67
...
...
@@ -6,6 +6,7 @@ using UnityEngine.AI;
public
class
PlayerController
:
SingletonBehaviour
<
PlayerController
>
{
public
Player
currentPlayer
;
public
bool
isPlayerMoving
;
// Start is called before the first frame update
void
Start
()
...
...
@@ -16,7 +17,7 @@ public class PlayerController : SingletonBehaviour<PlayerController>
// Update is called once per frame
void
Update
()
{
if
(
Input
.
GetMouseButtonDown
(
0
))
if
(
Input
.
GetMouseButtonDown
(
0
)
&&
!
isPlayerMoving
)
{
Ray
mouseRay
=
Camera
.
main
.
ScreenPointToRay
(
Input
.
mousePosition
);
RaycastHit
hit
;
...
...
@@ -25,7 +26,13 @@ public class PlayerController : SingletonBehaviour<PlayerController>
if
(
currentPlayer
!=
null
)
currentPlayer
.
ResetCurrentPlayer
();
currentPlayer
=
hit
.
transform
.
gameObject
.
GetComponent
<
Player
>();
currentPlayer
.
SetCurrentPlayer
();
StartCoroutine
(
currentPlayer
.
SetCurrentPlayer
());
Debug
.
Log
(
hit
.
collider
.
gameObject
.
tag
);
}
else
if
(
Physics
.
Raycast
(
mouseRay
,
out
hit
)
&&
hit
.
collider
.
gameObject
.
tag
.
Equals
(
"floor"
))
{
if
(
currentPlayer
!=
null
)
currentPlayer
.
MovePlayer
(
hit
.
collider
.
gameObject
.
transform
.
position
);
Debug
.
Log
(
hit
.
collider
.
gameObject
.
tag
);
}
else
if
(
hit
.
collider
==
null
)
...
...
@@ -33,12 +40,6 @@ public class PlayerController : SingletonBehaviour<PlayerController>
if
(
currentPlayer
!=
null
)
currentPlayer
.
ResetCurrentPlayer
();
}
/*if (Physics.Raycast(mouseRay, out hit) && hit.collider.gameObject.tag.Equals("floor"))
{
GetComponent<NavMeshAgent>().SetDestination(hit.collider.gameObject.transform.position);
Debug.Log(hit.collider.gameObject.GetComponent<Floor>().mapPos);
Debug.Log(hit.collider.gameObject.tag);
}*/
}
}
}
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