Beispiel #1
0
 private void Update()
 {
     if (flag == true)
     {
         if (flag2 == true)
         {
             flag2 = false;
             axe   = GameObject.FindGameObjectWithTag("Axe");
             fire  = GameObject.FindGameObjectsWithTag("Fire");
             start = new Location(transform.position.x, transform.position.y);
             goal  = new Location(axe.transform.position.x, axe.transform.position.y);
             this.createCost();
             graph = new SquareGrid(1, 1, 14, 14, costObject);
             astar = new AStarSearch2(graph, start, goal, costObject);
             path  = astar.FindPath();
             i     = 0;
         }
         time += Time.deltaTime;
         if (time > deltaT)
         {
             Tick();
             time  = 0;
             flag2 = true;
         }
     }
     if (flag == false)
     {
         axe = GameObject.FindGameObjectWithTag("Axe");
         if (axe == null)
         {
             fire = GameObject.FindGameObjectsWithTag("Fire");
             initMap();
             Instantiate(item, RandomPosition(), Quaternion.identity);
         }
         flag  = true;
         flag2 = true;
     }
 }
Beispiel #2
0
    protected override void Start()
    {
        animator                = GetComponent <Animator>();
        r2                      = GetComponent <Rigidbody2D>();
        r2.gravityScale         = 0;
        r2.rotation             = 0;
        ScoreScipt2.scoreValue2 = 0;

        wall  = GameObject.FindGameObjectsWithTag("Wall");
        floor = GameObject.FindGameObjectsWithTag("Floor");
        fire  = GameObject.FindGameObjectsWithTag("Fire");
        this.createCost();
        graph = new SquareGrid(1, 1, 14, 14, costObject);
        initMap();
        Instantiate(item, RandomPosition(), Quaternion.identity);
        axe    = GameObject.FindGameObjectWithTag("Axe");
        start  = new Location(transform.position.x, transform.position.y);
        goal   = new Location(axe.transform.position.x, axe.transform.position.y);
        astar  = new AStarSearch2(graph, start, goal, costObject);
        path   = astar.FindPath();
        deltaT = 1.0f * astar.dem / 80;
        base.Start();
    }