예제 #1
0
    public void Move(Node destNode, float speed, bool self = true)
    {
        this.speed    = speed;
        this.destNode = destNode;
        this.self     = self;
        Vector3 pos = GridContainer.NodeToPosition(node);

        moveDir   = (GridContainer.NodeToPosition(destNode) - pos).normalized;
        moveDir.x = moveDir.z = 0;
        moving    = true;
    }
예제 #2
0
    public static Grid Spawn(GridValue gridValue, Node node)
    {
        GameObject model = Resources.Load <GameObject>(gridValue == GridValue.grid_zero ? "Prefabs/Game/Rock" : "Prefabs/Game/Grid");
        GameObject grid  = GameObject.Instantiate <GameObject>(model);

        grid.transform.SetParent(PushBoxGame.Instance.gridContainer.transform);
        grid.transform.localScale = Vector3.one;
        Vector2 pos = GridContainer.NodeToPosition(node);

        grid.transform.localPosition = new Vector3(pos.x, pos.y, 0);
        Grid gridCom = grid.GetComponent <Grid>();

        gridCom.Value = gridValue;
        gridCom.Node  = node;
        //grid.GetComponent<RectTransform>().sizeDelta = new Vector2(GridContainer.GRID_WIDTH,GridContainer.GRID_HEIGHT);
        return(gridCom);
    }
예제 #3
0
 // Update is called once per frame
 void Update()
 {
     if (moving)
     {
         if (self)
         {
             if (GridContainer.NodeToPosition(destNode).y - 120 > transform.localPosition.y)
             {
                 Move();
             }
             else
             {
                 moving = false;
                 SetNode(destNode);
                 if (!PushBoxGame.Instance.gridContainer.Contains(this))
                 {
                     PushBoxGame.Instance.gridContainer.SelfGrids.Add(this);
                 }
                 PushBoxGame.Instance.CheckRemove(true);
             }
         }
         else
         {
             if (GridContainer.NodeToPosition(destNode).y + 120 <= transform.localPosition.y)
             {
                 Move();
             }
             else
             {
                 moving = false;
                 SetNode(destNode);
                 PushBoxGame.Instance.gridContainer.EnemyGrids.Add(this);
             }
         }
     }
 }
예제 #4
0
 public void SetNode(Node node)
 {
     this.node = node;
     transform.localPosition = GridContainer.NodeToPosition(node);
 }