public void SellObject(CollectableObject objectToSell) { WalkingUnit buyer = TriggerShop.GetNearestOne(); if (buyer == null) { print("Nobody is near"); return; } if (!buyer.faction.Equals(GameMaster.PlayerFaction)) { return; } if (buyer) { if (buyer && buyer.HasInventory() && (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost)) || (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost))) { bool objectSold = false; for (int i = 0; i < buyer.Inventory.Length; i++) { if (buyer.Inventory[i] == null) { if (buyer.faction.Equals(Faction.Blue) && (gameMaster.BlueWool >= objectToSell.MoneyCost)) { gameMaster.BlueWool -= objectToSell.MoneyCost; } else if (buyer.faction.Equals(Faction.Red) && (gameMaster.RedWool >= objectToSell.MoneyCost)) { gameMaster.RedWool -= objectToSell.MoneyCost; } else { Debug.LogError("Couldn't take money from red/blue wool when selling " + objectToSell + " to " + buyer.gameObject); } CollectableObject obj = Instantiate(objectToSell); obj.gameObject.SetActive(false); buyer.TakeObject(obj); objectSold = true; break; } } if (!objectSold) { print("Inventory full"); } } } }
public void OnUnitFinishMoving(WalkingUnit walkingUnit) { walkingUnit.MovingUnit.PositionFromParent = Vector2.Zero; walkingUnit.MovingUnit.DrawingTexture.SelectRow(0); // Get the tiles to move the Units from/to Tile targetTile = this[walkingUnit.TargetPosition] as Tile; Tile originTile = this[walkingUnit.MovingUnit.PositionInGrid] as Tile; // Move the Unit from its tile to the target tile targetTile.SetUnit(walkingUnit.MovingUnit); if (walkingUnit.RemoveOnEnd) { originTile.SetUnit(null); } }
private void CreateNewBuilding() { indexGO = EditorGUILayout.Popup("Model", indexGO, search_results); if (indexGO != actualIndexGO) { UpdateEveryFields(); } actualIndexGO = indexGO; if (skin && AssetPreview.GetAssetPreview(skin)) { EditorGUI.DrawPreviewTexture(new Rect(155, 25, 90, 90), AssetPreview.GetAssetPreview(skin)); } for (int i = 0; i < 20; i++) { EditorGUILayout.Space(); } nameUnit = EditorGUILayout.TextField("Name", nameUnit); defaultMaterial = (Material)EditorGUILayout.ObjectField("Default Material", defaultMaterial, typeof(Material), true); skin = (GameObject)EditorGUILayout.ObjectField("Skin", skin, typeof(GameObject), true); healthMax = EditorGUILayout.FloatField("Health Max", healthMax); manaMax = EditorGUILayout.FloatField("Mana Max", manaMax); regenManaPerSecond = EditorGUILayout.FloatField("Regen Mana Per Second", regenManaPerSecond); cost = EditorGUILayout.IntField("Cost", cost); xpValue = EditorGUILayout.FloatField("Xp value", xpValue); GUIStyle gstyle = new GUIStyle(EditorStyles.foldout); //showCreations = EditorGUILayout.Foldout(showCreations, "Creations", gstyle); //if (showCreations) //{ // for (int i = 0; i < inventory.Length; i++) // { // creations[i] = (AttackingUnit)EditorGUILayout.ObjectField(creations[i], typeof(AttackingUnit), true); // } //} creation = (WalkingUnit)EditorGUILayout.ObjectField(creation, typeof(WalkingUnit), true); isDumpingBuilding = EditorGUILayout.Toggle("Is Dumping Building", isDumpingBuilding); if (GUILayout.Button("Add new building")) { AddNewBuilding(); } }
public WalkingUnit GetNearestOne() { WalkingUnit nearestRTSGameObject = null; float minDistance = 9999; float distance = 0; for (int i = 0; i < NearsWalkingUnits.Count; i++) { if (NearsWalkingUnits[i] != null) { distance = Vector3.Distance(transform.position, NearsWalkingUnits[i].gameObject.transform.position); if (distance < minDistance) { minDistance = distance; nearestRTSGameObject = NearsWalkingUnits[i]; } } } return(nearestRTSGameObject); }
public override void Update(GameTime time) { base.Update(time); // Updates the Unit target overlay unitTargets.Update(time); hitEffectList.Update(time); // Remove unitTargets that are done unitTargets.ForEach(obj => { TargetPositionOverlay uto = obj as TargetPositionOverlay; if (uto.Finished) { unitTargets.RemoveChild(obj); } }); //If we have a selected unit; if there is a path to follow, we start walking using Walk(), otherwise we move to target location if (walkingUnits.Count > 0) { for (int i = walkingUnits.Count - 1; i >= 0; --i) { WalkingUnit walkingUnit = walkingUnits[i]; if (walkingUnit.MovingUnit.Vectors.Count > 0) { Walk(walkingUnit.MovingUnit, walkingUnit.MovingUnit.Vectors[0]); } else { OnUnitFinishMoving(walkingUnit); walkingUnits.Remove(walkingUnit); } } } }
public void UpdateEveryFields() { GameObject tmpShit = (GameObject)AssetDatabase.LoadAssetAtPath(search_results[indexGO], typeof(GameObject)); if (unitType.Equals(UnitType.AttackingUnit)) { AttackingUnit unit = tmpShit.GetComponent <AttackingUnit>(); nameUnit = unit.NameGo; unitType = unit.UnitType; defaultMaterial = unit.DefaultMaterial; //GameObject tmpSkin = new GameObject(); //tmpSkin.AddComponent<MeshFilter>(); //tmpSkin.GetComponent<MeshFilter>().mesh = unit.GetComponent<MeshFilter>().mesh; //skin = tmpSkin; //DestroyImmediate(tmpSkin); //skin regenManaPerSecond = unit.RegenManaPerSecond; healthMax = unit.HealthMax; manaMax = unit.ManaMax; cost = unit.Cost; xpValue = unit.XpValue; bool inventoryEmpty = true; for (int i = 0; i < unit.Inventory.Length; i++) { if (unit.Inventory[i] != null) { inventoryEmpty = false; } } if (!inventoryEmpty) { for (int i = 0; i < unit.Inventory.Length; i++) { inventory[i] = unit.Inventory[i]; } } creationTime = unit.CreationTime; attackSpeed = unit.AttackSpeed; damage = unit.Damage; range = unit.Range; defense = unit.Defense; rangeAggroWhenAttack = unit.RangeAggroWhenAttack; moveSpeed = unit.MoveSpeed; } else if (unitType.Equals(UnitType.Building)) { CreationBuilding unit = tmpShit.GetComponent <CreationBuilding>(); nameUnit = unit.NameGo; unitType = unit.UnitType; defaultMaterial = unit.DefaultMaterial; healthMax = unit.HealthMax; manaMax = unit.ManaMax; cost = unit.Cost; xpValue = unit.XpValue; creation = unit.Creations[0]; //bool creationsEmpties = true; //for (int i = 0; i < unit.Creations.Length; i++) //{ // if (unit.Creations[i] != null) // creationsEmpties = false; //} //if (!creationsEmpties) //{ // for (int i = 0; i < unit.Creations.Length; i++) // { // if (unit.Creations[i] != null) // creations[i] = unit.Creations[i]; // } //} } }
void Awake() { moveScript = GetComponent <UnitMove>(); self = GetComponent <WalkingUnit>(); }