Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class AStarPathfinding : MonoBehaviour {
- public GameObject NodePrefab;
- public int Height;
- public int Width;
- public GameObject[,] Graph;
- // Use this for initialization
- void Start () {
- Graph = new GameObject[Width,Height];
- //Generate Grid of Nodes
- float posX = 0f;
- float posY = 0f;
- for(int i =0; i<Width;i++)
- {
- for(int j = 0;j<Height;)
- {
- Graph[i,j] = (GameObject)Instantiate(NodePrefab,new Vector3(posX,posY),Quaternion.identity);
- Graph[i,j].transform.parent = this.transform;
- posX+=0.64f;
- }
- posY-=0.64f;
- posX = 0;
- }
- //Set Neighbours
- for(int y =0; y<Width;y++)
- {
- for(int x = 0;x<Height;x++)
- {
- Node n = Graph[y,x].GetComponent<Node>();
- //LEFT
- if(x>0)
- {
- n.AddNeighbour((Graph[y,x-1]));
- }
- //RIGHT
- if(x<Width-1)
- {
- //n.AddNeighbour(Graph[y,x+1]);
- }
- //TOP
- if(y>0)
- {
- //n.AddNeighbour(Graph[y-1,x]);
- }
- //BOT
- if(y<Height-1)
- {
- //n.AddNeighbour(Graph[y+1,x]);
- }
- //TOPLEFT
- //TOPRIGHT
- //BOTLEFT
- //BOTRIGHT
- }
- }
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement