コード例 #1
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 positionSouris = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            //pathfinding.getGrid().GetXY(positionSouris, out int x, out int y);

            Vector3 positionPlayer = new Vector3(player.transform.position.x, player.transform.position.y);
            Vector3 positionEnemy  = new Vector3(enemy.transform.position.x, enemy.transform.position.y);

            Debug.Log("Player is on : x, " + positionPlayer.x + ", y : " + positionPlayer.y);

            //Ça pète ici !!!!!
            grid.GetXY(positionPlayer, out int z, out int w);
            grid.GetXY(positionEnemy, out int x, out int y);


            List <NatNode> path = pathfinding.FindPath(z, w, x, y);

            if (path != null)
            {
                for (int i = 0; i < path.Count - 1; i++)
                {
                    Debug.DrawLine(new Vector3(path[i].x, path[i].y) * 0.5f + Vector3.one * 0.25f + new Vector3(4, 0.5f), new Vector3(path[i + 1].x, path[i + 1].y) * 0.5f + Vector3.one * 0.25f + new Vector3(4, 0.5f), Color.green, 5f);
                }
            }
        }
    }
コード例 #2
0
    public void bougerRadom()
    {
        //float rangeAttaque = Vector2.Distance(transform.position, player.transform.position);

        pathfinding.getGrid().GetXY(transform.position, out int x, out int y);


        int randomx = Random.Range(rangeIAMin, rangeIAMax);
        int randomy = Random.Range(rangeIAMin, rangeIAMax);


        while ((x + randomx) >= largeur || ((x + randomx) <= 0))
        {
            randomx = Random.Range(rangeIAMin, rangeIAMax);
        }

        while ((y + randomy) >= hauteur || (y + randomy) <= 0)
        {
            randomx = Random.Range(rangeIAMin, rangeIAMax);
        }

        path = pathfinding.FindPath(x, y, x + randomx, y + randomy);
    }