55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class MapDot : MonoBehaviour
|
|||
|
{
|
|||
|
|
|||
|
public GameObject pelletPrefab;
|
|||
|
public LayerMask ObstadeLayer;
|
|||
|
|
|||
|
public GameObject startPosGameObject;
|
|||
|
public GameObject endPosGameObject;
|
|||
|
public Vector2 startPos;
|
|||
|
public Vector2 endPos;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
startPos = startPosGameObject.transform.position;
|
|||
|
endPos = endPosGameObject.transform.position;
|
|||
|
GeneratePellets();
|
|||
|
}
|
|||
|
|
|||
|
void GeneratePellets()
|
|||
|
{
|
|||
|
/*int minX = Mathf.FloorToInt(Mathf.Min(startPos.x, endPos.x));
|
|||
|
int maxX = Mathf.CeilToInt(Mathf.Max(startPos.x, endPos.x));
|
|||
|
int minY = Mathf.FloorToInt(Mathf.Min(startPos.y, endPos.y));
|
|||
|
int maxY = Mathf.CeilToInt(Mathf.Max(startPos.y, endPos.y));*/
|
|||
|
float minX = Mathf.Min(startPos.x, endPos.x);
|
|||
|
float maxX = Mathf.Max(startPos.x, endPos.x);
|
|||
|
float minY = Mathf.Min(startPos.y, endPos.y);
|
|||
|
float maxY = Mathf.Max(startPos.y, endPos.y);
|
|||
|
|
|||
|
for (float x = minX; x <= maxX; x++)
|
|||
|
{
|
|||
|
for (float y = minY; y <= maxY; y++)
|
|||
|
{
|
|||
|
Vector2 checkPos = new Vector2(x, y);
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD>Wall<6C><6C><EFBFBD><EFBFBD>ײ<EFBFBD><D7B2>
|
|||
|
Collider2D hit = Physics2D.OverlapBox(checkPos, Vector2.one * 0.1f, 0, ObstadeLayer);
|
|||
|
if (hit == null)
|
|||
|
{
|
|||
|
Instantiate(pelletPrefab, checkPos, Quaternion.identity, transform);
|
|||
|
GameManager.instance.AddDotNum(1);
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|