Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class Generation : MonoBehaviour {
- public GameObject GroundObject;
- GameObject block;
- GameObject SelectedObject;
- public GameObject Curser;
- public int width;
- public int length;
- int i = 0;
- [Range(0,1)]
- public float gridSpacing;
- Vector2[] mappedPositions;
- public Vector2 gridPosition;
- void CreateStage() {
- mappedPositions = new Vector2[width * length];
- for(int x = 0; x < length; x++)
- {
- for(int y = 0; y < width; y++)
- {
- block = (GameObject)Instantiate (GroundObject, new Vector3 (x+(gridSpacing*x), 0, y+(gridSpacing*y)), Quaternion.identity);
- block.name = "X:"+ x + " " + "Y:" + y;
- mappedPositions[i].x = x;
- mappedPositions[i].y = y;
- i++;
- }
- }
- Camera.main.transform.position = new Vector3(length / 2, 20, width / 2);
- }
- void MoveSquare()
- {
- if(Input.GetKeyDown(KeyCode.UpArrow))
- {
- if(gridPosition.y != length - 1)
- {
- gridPosition.y++;
- }
- }
- if(Input.GetKeyDown(KeyCode.DownArrow))
- {
- if(gridPosition.y != 0)
- {
- gridPosition.y--;
- }
- }
- if(Input.GetKeyDown(KeyCode.LeftArrow))
- {
- if(gridPosition.x != 0)
- {
- gridPosition.x--;
- }
- }
- if(Input.GetKeyDown(KeyCode.RightArrow))
- {
- if(gridPosition.x != width - 1)
- {
- gridPosition.x++;
- }
- }
- }
- void Start () {
- CreateStage();
- gridPosition = new Vector2(0,0);
- }
- void Update () {
- MoveSquare();
- SelectedObject = GameObject.Find("X:"+ gridPosition.x +" Y:" + gridPosition.y);
- Curser.transform.position = new Vector3(SelectedObject.transform.position.x, 2, SelectedObject.transform.position.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment