Esempio n. 1
0
    void Awake()
    {
        gridCanvas  = GetComponentInChildren <Canvas>();
        hexagonMesh = GetComponentInChildren <HexagonMesh>();

        navMeshGen = new NavmeshGen();

        cells = new HexagonCellGen[height * width];

        for (int z = 0, i = 0; z < height; z++)
        {
            for (int x = 0; x < width; x++)
            {
                CreateCell(x, z, i++);
            }
        }

        navMeshGen.GenNavMesh();
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (needsToGetNewTarget)
        {
            // Find new target
            //target = hexagonManager.GetBestHexagonDistanceScaled(computer.GetComponent<ComputerMesh>().GetCurAngle());
            target = hexagonManager.GetBestHexagonPeriod();
            Vector2 shootingData = target.GetShootingAngle(computer.GetComponent <ComputerMesh>().GetCurAngle());
            moveToAngle  = shootingData[0];
            shootAtAngle = shootingData[1];


            // Tell ComputerMesh to move there
            computer.GetComponent <ComputerMesh>().SetTargetAngle(moveToAngle);

            Debug.Log("Moving to angle " + moveToAngle.ToString() + ", shooting at number " + target.GetNumber());

            needsToGetNewTarget = false;
            isMoving            = true;
        }
        if (!isMoving && !missileIsActive && !needsToGetNewTarget)
        {
            FireMissile();

            missileIsActive     = true;
            isMoving            = false;
            needsToGetNewTarget = true;
        }

        // Check if missile is too far away
        if (missile && Vector2.Distance(missile.transform.position, Vector2.zero) > trackRadius + 1)
        {
            Destroy(missile);
            missileIsActive     = false;
            needsToGetNewTarget = true;
        }
    }
Esempio n. 3
0
 // Use this for initialization
 void Awake()
 {
     gridCanvas = GetComponentInChildren <Canvas>();
     hexMesh    = GetComponentInChildren <HexagonMesh>();
     CreateGrid();
 }