Initial commit
This commit is contained in:
69
Assets/scripts/gridGen.cs
Normal file
69
Assets/scripts/gridGen.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class gridGen : MonoBehaviour
|
||||
{
|
||||
public perlinNoise noise;
|
||||
public GameObject hexPrefab;
|
||||
public Transform mapStart;
|
||||
private float translationVert;
|
||||
|
||||
public int x = 32;
|
||||
public int y = 32;
|
||||
|
||||
private float scaleY = Mathf.Sqrt(3) / 2;
|
||||
private float scaleX = 1;
|
||||
|
||||
private int nowX;
|
||||
private int nowY;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
/*
|
||||
GameObject hex2 = Instantiate(hexPrefab);
|
||||
hex2.transform.Translate(new Vector3(0, scaleY, 0));
|
||||
|
||||
GameObject hex3 = Instantiate(hexPrefab);
|
||||
hex3.transform.Translate(new Vector3(0.75f*scaleX, 0.5f*scaleY, 0));
|
||||
*/
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (nowX < x)
|
||||
{
|
||||
|
||||
while (nowY < y)
|
||||
{
|
||||
float modX = 0.25f;
|
||||
float modY = 0;
|
||||
|
||||
if (nowX % 2 == 1)
|
||||
{
|
||||
modY = 0.5f;
|
||||
}
|
||||
|
||||
|
||||
initHex(mapStart.position.x + (scaleX * nowX) - (modX*scaleX*nowX), mapStart.position.y + (scaleY * nowY) + (modY*scaleY));
|
||||
nowY++;
|
||||
}
|
||||
|
||||
{
|
||||
nowX++;
|
||||
nowY = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initHex(float x, float y)
|
||||
{
|
||||
GameObject hex = Instantiate(hexPrefab);
|
||||
hex.transform.Translate(new Vector3(x, y, 0));
|
||||
hex.GetComponent<cell>().noiseValue = noise.getNoise((float) nowX/this.x, (float) nowY /this.x, Mathf.Max(this.x, this.y));
|
||||
hex.GetComponent<cell>().Init();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user