Commit cdc21c09 authored by 18손재민's avatar 18손재민

바닥 및 벽 생성하는 메소드 구현 중, 이거 실행하면 에러남

parent e098f997
......@@ -48,6 +48,7 @@ MonoBehaviour:
floor: {fileID: 4430576614521234720, guid: 71931eea896a59a4683986cfd369b8ee, type: 3}
wall: {fileID: 337530617404887312, guid: a4dcd71ec9f819f4e88c7b5ac24f4b0d, type: 3}
player: {fileID: 0}
map: {fileID: 0}
surface: {fileID: 0}
xInput: {fileID: 0}
yInput: {fileID: 0}
......@@ -294,6 +294,36 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c7d507df55441f7438f6f059e9d2587c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1505663513
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1505663514}
m_Layer: 0
m_Name: Map
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1505663514
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1505663513}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2, y: 0.6, z: 2.5000021}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1513534067 stripped
MonoBehaviour:
m_CorrespondingSourceObject: {fileID: 1444571408487427165, guid: 0b18400fb62a12d4e9cb5fbb8ecbb53f,
......@@ -761,6 +791,11 @@ PrefabInstance:
propertyPath: yInput
value:
objectReference: {fileID: 1513534067}
- target: {fileID: 6014610519130626207, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: map
value:
objectReference: {fileID: 1505663513}
- target: {fileID: 6014610519130626206, guid: 11285456de5f1854d947bea83275646f,
type: 3}
propertyPath: m_LocalPosition.x
......
......@@ -4,6 +4,18 @@ using UnityEngine;
public class CameraController : MonoBehaviour
{
void CameraMove()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
transform.position += new Vector3(verticalInput + horizontalInput, 0, verticalInput - horizontalInput);
}
void CameraRotate()
{
}
// Start is called before the first frame update
void Start()
{
......@@ -13,8 +25,7 @@ public class CameraController : MonoBehaviour
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
transform.position += new Vector3(verticalInput + horizontalInput, 0, verticalInput - horizontalInput);
CameraMove();
CameraRotate();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Map : MonoBehaviour
{
//Remove when singleton added.
public MapManager mapManager;
//Remove when singleton added.
public int maxMapSize;
public int mapCenterPos;
public GameObject[,] floorGrid;
/// <summary>
/// Get floor at position.
/// </summary>
/// <param name="x">X position of floor.</param>
/// <param name="y">Y position of floor.</param>
/// <returns></returns>
public GameObject GetFloorAtPos(int x, int y)
{
if (floorGrid[mapCenterPos + x, mapCenterPos + y] != null)
return floorGrid[mapCenterPos + x, mapCenterPos + y];
else
return null;
}
/// <summary>
/// Get floor at position.
/// </summary>
/// <param name="pos">Position of floor.</param>
/// <returns></returns>
public GameObject GetFloorAtPos(Vector2Int pos)
{
return GetFloorAtPos(pos.x, pos.y);
}
/// <summary>
/// Create floor at position.
/// </summary>
/// <param name="x">X position of floor.</param>
/// <param name="y">Y position of floor.</param>
public void CreateFloor(int x, int y)
{
if(floorGrid[mapCenterPos + x, mapCenterPos + y] == null)
{
floorGrid[mapCenterPos + x, mapCenterPos + y] = Instantiate(mapManager.floor, new Vector3(mapCenterPos + x, 0, mapCenterPos + y), Quaternion.identity, transform);
}
else
{
Debug.Log("Floor already exists in : (" + x + ", " + y + ")");
}
}
/// <summary>
/// Create floor at position.
/// </summary>
/// <param name="pos">Position of floor.</param>
public void CreateFloor(Vector2Int pos)
{
CreateFloor(pos.x, pos.y);
}
/// <summary>
/// Remove floor at position.
/// </summary>
/// <param name="x">X position of floor.</param>
/// <param name="y">Y position of floor.</param>
public void RemoveFloor(int x, int y)
{
if (floorGrid[mapCenterPos + x, mapCenterPos + y] != null)
{
Destroy(floorGrid[mapCenterPos + x, mapCenterPos + y].gameObject);
}
else
{
Debug.Log("Floor doesn't exists in : (" + x + ", " + y + ")");
}
}
/// <summary>
/// Remove floor at position.
/// </summary>
/// <param name="pos">Position of floor.</param>
public void RemoveFloor(Vector2Int pos)
{
RemoveFloor(pos.x, pos.y);
}
public void CreateWall(GameObject cube1, GameObject cube2)
{
}
public void Rebaker()
{
surface.BuildNavMesh();
}
/// <summary>
/// Create wall between two cubes.
/// </summary>
/// <param name="cube1">Cube 1</param>
/// <param name="cube2">Cube 2</param>
public void CreateWall(GameObject cube1, GameObject cube2)
{
Vector3 wallPos = (cube1.transform.position + cube2.transform.position) / 2;
GameObject abc = Instantiate(wall, wallPos, Quaternion.identity, transform);
abc.transform.LookAt(cube1.transform);
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
fileFormatVersion: 2
guid: aa2c12f6bf26415469ec088e3e4c4dc3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -10,33 +10,22 @@ public class MapManager : MonoBehaviour
public GameObject floor;
public GameObject wall;
public GameObject player;
public GameObject[,] mapGrid;
public NavMeshSurface surface;
public Map currentMap;
public static NavMeshSurface surface;
public Map[] stage;
public InputField xInput, yInput;
public void Rebaker()
{
surface.BuildNavMesh();
}
public void RemoveTile()
public void CreateMap(Map _newMap)
{
if (mapGrid[int.Parse(xInput.text), int.Parse(yInput.text)] != null)
{
Destroy(mapGrid[int.Parse(xInput.text), int.Parse(yInput.text)].gameObject);
surface.BuildNavMesh();
}
else
Debug.Log("Tile doesn't exists");
Map newMap = Instantiate(_newMap);
newMap.transform.position = new Vector3(0, 0, 0);
}
public void AddTile()
public void Rebaker()
{
if (mapGrid[int.Parse(xInput.text), int.Parse(yInput.text)] == null)
{
mapGrid[int.Parse(xInput.text), int.Parse(yInput.text)] = Instantiate(floor, new Vector3(int.Parse(xInput.text), 0, int.Parse(yInput.text)), Quaternion.identity, transform);
surface.BuildNavMesh();
}
else
Debug.Log("Tile already exists");
surface.BuildNavMesh();
}
/// <summary>
/// Create wall between two cubes.
......@@ -51,20 +40,25 @@ public class MapManager : MonoBehaviour
}
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
mapGrid = new GameObject[100, 100];
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
mapMaxSize = 5 * Mathf.Max(x, y);
mapCenterPos = mapMaxSize / 2;
mapGrid = new GameObject[mapMaxSize, mapMaxSize];
for (int i = mapCenterPos; i < mapCenterPos + x; i++)
for (int j = mapCenterPos; j < mapCenterPos + y; j++)
mapGrid[i, j] = Instantiate(floor, new Vector3(i, 0, j), Quaternion.identity, transform);
CreateWall(mapGrid[2, 2], mapGrid[2, 3]);
CreateWall(mapGrid[3, 2], mapGrid[2, 2]);
CreateWall(mapGrid[3, 3], mapGrid[2, 3]);
player.transform.position = GetCubeAtPos(0, 0).transform.position + new Vector3(0, 1.5f, 0);
CreateWall(GetCubeAtPos(2, 2), GetCubeAtPos(2, 3));
CreateWall(GetCubeAtPos(3, 2), GetCubeAtPos(2, 2));
CreateWall(GetCubeAtPos(3, 3), GetCubeAtPos(2, 3));
surface.BuildNavMesh();
player.transform.position = mapGrid[0, 0].transform.position + new Vector3(0, 1.5f, 0);
}
// Update is called once per frame
......
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