Example #1
0
    void selected_game_object_right_click()
    {
        if (selected_gameobject.tag == "Character")
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitinfo;

            LayerMask layer = LayerMask.GetMask("Building", "Character", "Ground");
            if (Physics.Raycast(ray, out hitinfo, Mathf.Infinity, layer))
            {
                //CharacterController character_controller = selected_gameobject.GetComponent<CharacterController>();
                CharacterAI character_ai = selected_gameobject.GetComponent <CharacterAI>();
                if (hitinfo.transform.gameObject.tag == "Ground")
                {
                    //NavMeshAgent nav_mesh_agent = selected_gameobject.GetComponent<NavMeshAgent>();

                    //if (Vector3.Distance(nav_mesh_agent.destination, hitinfo.point) >= 0.1)
                    //{
                    //nav_mesh_agent.SetDestination(hitinfo.point);
                    //character_controller.move_to(hitinfo.point);
                    character_ai.add_priority_task(new Task(hitinfo.point));
                    LogBox.get_log_box().AddEvent("Character moving to " + hitinfo.point);
                    //}
                }
                else if (hitinfo.transform.gameObject.tag == "Building")
                {
                    GameObject building_gameobject = GetGameObjectFromCollider(hitinfo.transform.gameObject);
                    Building   building            = building_gameobject.GetComponent <Building>();
                    character_ai.add_priority_task(new Task(building));

                    /*
                     * Transform entrance = hitinfo.transform.gameObject.transform.parent.Find("Entrance");
                     * Debug.Log(entrance.position);
                     * if (entrance)
                     * {
                     *  //NavMeshAgent nav_mesh_agent = selected_gameobject.GetComponent<NavMeshAgent>();
                     *  //nav_mesh_agent.SetDestination( entrance.position );
                     *  character_controller.move_to(entrance.position);
                     * }
                     * else
                     *  Debug.Log("Cannot find Entrance from " + hitinfo.transform.gameObject.transform.parent.name);
                     */
                }
            }
        }
    }
Example #2
0
    void build_at(Vector3 tile_position)
    {
        detach_arrow();

        Building building = building_cursor.GetComponent <Building>();

        int x_bound = 0;
        int z_bound = 0;

        if (building.direction == Direction.Up || building.direction == Direction.Down)
        {
            x_bound = building.size_x;
            z_bound = building.size_z;
        }
        else if (building.direction == Direction.Right || building.direction == Direction.Left)
        {
            x_bound = building.size_z;
            z_bound = building.size_x;
        }

        for (int x = 0; x < x_bound; ++x)
        {
            for (int y = 0; y < z_bound; ++y)
            {
                Vector2 pos = new Vector2(tile_position.x + x, tile_position.z + y);
                if (tile_map.GetComponent <TileMap>().tile_info_.ContainsKey(pos))
                {
                    TileInfo info = tile_map.GetComponent <TileMap>().tile_info_ [pos];
                    info.building = building_cursor;
                }
            }
        }



        building_cursor.GetComponentInChildren <MeshRenderer> ().material.color = Color.gray;

        building_cursor = Instantiate(building_cursor, this.transform);
        building_cursor.GetComponentInChildren <MeshRenderer> ().material.color = Color.red;
        attach_arrow();
        LogBox.get_log_box().AddEvent("Built " + building_cursor.name);
    }