mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-11-11 18:13:54 +01:00
merloj: tilemapy stuffy
- collider tilempawoy - rysowanie ustalonej wielkości mapy
This commit is contained in:
parent
39c0b33131
commit
7cc7000a67
@ -26,9 +26,9 @@ Transform:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 403095692180922766}
|
m_GameObject: {fileID: 403095692180922766}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 0.99, y: 0.99, z: 0.99}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
m_Children:
|
m_Children:
|
||||||
- {fileID: 5390027776247701102}
|
- {fileID: 5390027776247701102}
|
||||||
@ -36,7 +36,7 @@ Transform:
|
|||||||
- {fileID: 4966879261024258644}
|
- {fileID: 4966879261024258644}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
|
||||||
--- !u!65 &2567001691605468863
|
--- !u!65 &2567001691605468863
|
||||||
BoxCollider:
|
BoxCollider:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -26,7 +26,7 @@ Transform:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 403095692180922766}
|
m_GameObject: {fileID: 403095692180922766}
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||||
m_ConstrainProportionsScale: 0
|
m_ConstrainProportionsScale: 0
|
||||||
@ -36,7 +36,7 @@ Transform:
|
|||||||
- {fileID: 5994269345490125713}
|
- {fileID: 5994269345490125713}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_RootOrder: 0
|
m_RootOrder: 0
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
|
||||||
--- !u!65 &2567001691605468863
|
--- !u!65 &2567001691605468863
|
||||||
BoxCollider:
|
BoxCollider:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,7 @@ public class TilemapManager : MonoBehaviour
|
|||||||
[SerializeField] private Tilemap tilemap = null;
|
[SerializeField] private Tilemap tilemap = null;
|
||||||
[SerializeField] private GameObject soldierPrefab = null;
|
[SerializeField] private GameObject soldierPrefab = null;
|
||||||
[SerializeField] private GameObject basePrefab = null;
|
[SerializeField] private GameObject basePrefab = null;
|
||||||
|
[SerializeField] private TileBase[] tilesToDraw = null;
|
||||||
|
|
||||||
// private (do not edit) variables
|
// private (do not edit) variables
|
||||||
|
|
||||||
@ -55,6 +56,14 @@ public class TilemapManager : MonoBehaviour
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
|
//draw tilemap
|
||||||
|
TileBase[] tilesToDrawTemp = new TileBase[mapSize.x * mapSize.y];
|
||||||
|
for (int i=0; i<tilesToDrawTemp.Length; i++)
|
||||||
|
{
|
||||||
|
tilesToDrawTemp[i] = tilesToDraw[Random.Range(0, tilesToDraw.Length)];
|
||||||
|
}
|
||||||
|
tilemap.SetTilesBlock(new BoundsInt(0, 0, 0, mapSize.x, mapSize.y, 1), tilesToDrawTemp);
|
||||||
|
|
||||||
//spawn bases
|
//spawn bases
|
||||||
SpawnSoldier(allyBaseCoord.x, allyBaseCoord.y, true, true);
|
SpawnSoldier(allyBaseCoord.x, allyBaseCoord.y, true, true);
|
||||||
SpawnSoldier(enemyBaseCoord.x, enemyBaseCoord.y, false, true);
|
SpawnSoldier(enemyBaseCoord.x, enemyBaseCoord.y, false, true);
|
||||||
@ -101,9 +110,9 @@ public class TilemapManager : MonoBehaviour
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (isBase)
|
if (isBase)
|
||||||
tiles[x, y].standingEntity = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Base>();
|
tiles[x, y].standingEntity = Instantiate(basePrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, basePrefab.transform.rotation).GetComponent<Base>();
|
||||||
else
|
else
|
||||||
tiles[x, y].standingEntity = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, Quaternion.identity).GetComponent<Soldier>();
|
tiles[x, y].standingEntity = Instantiate(soldierPrefab, tilemap.CellToWorld(new Vector3Int(x, y, 0)) + WORLD_SPACE_OFFSET, soldierPrefab.transform.rotation).GetComponent<Soldier>();
|
||||||
|
|
||||||
if (tiles[x, y].standingEntity == null)
|
if (tiles[x, y].standingEntity == null)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -35,10 +35,25 @@ public class PlayerClickSystem : MonoBehaviour
|
|||||||
Camera camera = Camera.main;
|
Camera camera = Camera.main;
|
||||||
RaycastHit hit;
|
RaycastHit hit;
|
||||||
Ray ray = camera.ScreenPointToRay(mousePos);
|
Ray ray = camera.ScreenPointToRay(mousePos);
|
||||||
|
RaycastHit2D hit2D = Physics2D.GetRayIntersection(ray);
|
||||||
|
|
||||||
|
Vector3 tileCoord = new Vector3(-1, -1, -1);
|
||||||
|
bool hitted = false;
|
||||||
|
|
||||||
if (Physics.Raycast(ray, out hit))
|
if (Physics.Raycast(ray, out hit))
|
||||||
{
|
{
|
||||||
Vector3 hitWorldPosition = hit.point;
|
tileCoord = hit.point;
|
||||||
|
hitted = true;
|
||||||
|
}
|
||||||
|
else if (hit2D.collider != null)
|
||||||
|
{
|
||||||
|
tileCoord = hit2D.point;
|
||||||
|
hitted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitted)
|
||||||
|
{
|
||||||
|
Vector3 hitWorldPosition = tileCoord;
|
||||||
|
|
||||||
Debug.Log($"Hit at {hitWorldPosition}");
|
Debug.Log($"Hit at {hitWorldPosition}");
|
||||||
TilemapManager.Tile selectedTile;
|
TilemapManager.Tile selectedTile;
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 13b75c95f34a00d4e8c04f76b73312e6, type: 3}
|
|
||||||
m_Name: New Animated Tile
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_AnimatedSprites: []
|
|
||||||
m_MinSpeed: 1
|
|
||||||
m_MaxSpeed: 1
|
|
||||||
m_AnimationStartTime: 0
|
|
||||||
m_AnimationStartFrame: 0
|
|
||||||
m_TileColliderType: 0
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 3b3905470e7d3cc4c9a6dae3aab82ab8
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
Loading…
Reference in New Issue
Block a user