Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MoveAreaController : MonoBehaviour {
  6.  
  7. public MainController MainControllerInst;
  8. public static List<MoveAreaController> areas = new List<MoveAreaController>();
  9. public MoveAreaController moveareas;
  10.  
  11. // Use this for initialization
  12. void Start () {
  13. MainControllerInst = GameObject.Find("MainController").GetComponent<MainController>();
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18. if (MainControllerInst.statusFlag == 2) {
  19. this.ShowMoveArea();
  20. }
  21. if (MainControllerInst.statusFlag == 4) {
  22. this.ClearMoveArea();
  23. }
  24. }
  25.  
  26. public void ShowMoveArea() {
  27. //移動範囲にオブジェクトを作成
  28. CubeController cubeControllerInst = GameObject.Find("Cube").GetComponent<CubeController>();
  29. Vector3 nowVec3Pos = cubeControllerInst.transform.position;
  30.  
  31. MoveAreaController areatemp;
  32.  
  33. areatemp = Instantiate(this, new Vector3(nowVec3Pos.x - 1.0f, nowVec3Pos.y -0.49f, nowVec3Pos.z), Quaternion.identity);
  34. areas.Add(areatemp);
  35. areatemp = Instantiate(this, new Vector3(nowVec3Pos.x + 1.0f, nowVec3Pos.y - 0.49f, nowVec3Pos.z), Quaternion.identity);
  36. areas.Add(areatemp);
  37. areatemp = Instantiate(this, new Vector3(nowVec3Pos.x, nowVec3Pos.y - 0.49f, nowVec3Pos.z - 1.0f), Quaternion.identity);
  38. areas.Add(areatemp);
  39. areatemp = Instantiate(this, new Vector3(nowVec3Pos.x, nowVec3Pos.y - 0.49f, nowVec3Pos.z + 1.0f), Quaternion.identity);
  40. areas.Add(areatemp);
  41.  
  42. //MainController MainControllerInst = GameObject.Find("MainController").GetComponent<MainController>();
  43. MainControllerInst.statusFlag = 3;
  44. }
  45.  
  46. public void ClearMoveArea() {
  47.  
  48. if(areas.Count > 1) {
  49. for(int i = areas.Count -1; i >= 0; --i) {
  50. Destroy(areas[i].gameObject);
  51. areas.RemoveAt (i);
  52. }
  53. }
  54.  
  55. MainControllerInst.statusFlag = 0;
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement