Пример #1
0
    public void DesroyUnit(Unit u)
    {
        GameObject unitGO = UnitToGo[u];

        GameObject.Destroy(unitGO);
        UnitToGo.Remove(u);
        Units.Remove(u);
    }
Пример #2
0
    public void SpawnUnitAt(string type, int q, int r)
    {
        if (!UnitTypes.ContainsKey(type))
        {
            Debug.LogError("There is no such thing as a " + type);
            return;
        }

        Unit UType = UnitTypes[type];
        Unit unit  = new Unit(UType);

        unit.Hex      = GetHexAt(q, r);
        unit.Hex.unit = unit;
        GameObject UnitGO = GameObject.Instantiate(UnitPrefabs[type], HexToGo[unit.Hex].transform);

        try
        {
            Mesh mesh = (Mesh)Resources.Load("Models/MapObjects/Units/" + type, typeof(Mesh));
            UnitGO.GetComponentInChildren <MeshFilter>().mesh         = mesh;
            UnitGO.GetComponentInChildren <MeshCollider>().sharedMesh = mesh;
            //ONLY USES ONE MESH
        }
        catch (Exception e)
        {
            Debug.Log(e);
            Mesh mesh = (Mesh)Resources.Load("Models/MapObjects/Units/Unit", typeof(Mesh));
            UnitGO.GetComponentInChildren <MeshFilter>().mesh         = mesh;
            UnitGO.GetComponentInChildren <MeshCollider>().sharedMesh = mesh;
        }
        UnitGO.GetComponent <UnitView>().Unit = unit;
        UnitGO.name = unit.Name + " " + unit.Hex;
        UnitToGo.Add(unit, UnitGO);
        Units.Add(unit);
        unit.OnUnitMoved += UpdateFogOfWar;
        unit.OnUnitMoved += unit.ClearSleep;
        UpdateFogOfWar(unit);
        unit.OnObjectDestroyed += DesroyUnit;
    }