Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GameController : MonoBehaviour {
  6.  
  7. public Entity player;
  8. public Transform grid;
  9.  
  10. float testTimer = 5f;
  11.  
  12. void Start() {
  13. MoveEntity(player, 1, 1);
  14. }
  15.  
  16. void Update() {
  17. testTimer -= Time.deltaTime;
  18. if(testTimer<0){
  19. MoveEntity(player, 5, 5);
  20. }
  21. }
  22.  
  23. Transform GetSpace(int x, int y) {
  24. return grid.GetChild(y - 1).GetChild(x - 1);
  25. }
  26.  
  27. void MoveEntity(Entity entity, int x, int y) {
  28. entity.locationX = x;
  29. entity.locationY = y;
  30. entity.transform.SetParent(GetSpace(x, y));
  31. }
  32.  
  33. public void ReceiveTileInput(GameObject tile) {
  34. int[] location = GetTileLocation(tile.transform);
  35. MoveEntity(player, location[0], location[1]);
  36. }
  37.  
  38. int[] GetTileLocation(Transform tileTransform) {
  39. return new int[] {tileTransform.parent.GetSiblingIndex() + 1, tileTransform.parent.parent.GetSiblingIndex() + 1};
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement