void Awake() { audioSource = GetComponent<AudioSource>(); animator = GetComponent<Animator>(); _unitMoveScript = GetComponent<UnitMove>(); self = GetComponent<AttackingUnit>(); }
public void SpawnEnemy(AttackingUnit enemy, Vector3 position) { var ai = enemyAIFactory.Create(enemy.Prefab[0]); ai.transform.position = position; ai.Init(enemy); enemyHolder.AddNewUnit(ai.gameObject); }
public int Damage(AttackingUnit enemy, int damage) { damage -= enemy.Def; enemy.Hp -= damage; if (enemy.Hp < 0) { enemy.Hp = 0; } return(damage); }
public void AttackEnemy(AttackingUnit enemy) { if (enemy != null && !enemy.DodgeAttack()) { int atkDamage; int chance = r.Next(1, 101); if (chance <= Crit) { atkDamage = critDamage(); } else { atkDamage = Atk; } atkDamage = Damage(enemy, atkDamage); Debug.Log(this.GetType().ToString() + " did " + atkDamage + " to the " + enemy.GetType().ToString()); } else { Debug.Log("The " + enemy.GetType().ToString() + " dodged!"); } }
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]; // } //} } }
public static void AddNewAttackingUnit() { GameObject emptyGO = new GameObject(); AssetDatabase.CreateFolder("Assets/Prefabs", nameUnit); GameObject tmp = PrefabUtility.CreatePrefab("Assets/Prefabs/" + nameUnit + "/" + nameUnit + ".prefab", emptyGO); tmp.AddComponent <NavMeshAgent>(); tmp.AddComponent <Rigidbody>(); tmp.AddComponent <Animator>(); tmp.AddComponent <AudioSource>(); AttackingUnit atunit = tmp.AddComponent <AttackingUnit>(); atunit.NameGo = nameUnit; atunit.UnitType = unitType; atunit.DefaultMaterial = defaultMaterial; atunit.RegenManaPerSecond = regenManaPerSecond; Material inAreaUnit = (Material)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Skills/InAreaUnit.mat", typeof(Material)); GameObject smallHealthBar = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/HealthBar/HealthBar.prefab", typeof(GameObject)); atunit.InAreaMaterial = inAreaUnit; atunit.SmallHealthBarPrefab = smallHealthBar; atunit.HealthMax = healthMax; atunit.ManaMax = manaMax; atunit.Cost = cost; atunit.XpValue = xpValue; bool inventoryEmpty = true; for (int i = 0; i < inventory.Length; i++) { if (inventory[i] != null) { inventoryEmpty = false; } } if (!inventoryEmpty) { atunit.Inventory = new CollectableObject[6]; for (int i = 0; i < atunit.Inventory.Length; i++) { atunit.Inventory[i] = inventory[i]; } } atunit.CreationTime = creationTime; atunit.AttackSpeed = attackSpeed; atunit.Damage = damage; atunit.Range = range; atunit.Defense = defense; atunit.RangeAggroWhenAttack = rangeAggroWhenAttack; atunit.MoveSpeed = moveSpeed; NavMeshAgent navmesh = tmp.GetComponent <NavMeshAgent>(); navmesh.speed = moveSpeed; navmesh.angularSpeed = 200; navmesh.acceleration = 100; navmesh.stoppingDistance = 0; navmesh.obstacleAvoidanceType = ObstacleAvoidanceType.MedQualityObstacleAvoidance; GameObject instantiatedTmp = Instantiate(tmp); if (skin) { Instantiate(skin, instantiatedTmp.transform); } GameObject aggro = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Aggro/Aggro.prefab", typeof(GameObject)); GameObject projector = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Projector/ProjectorPrefab.prefab", typeof(GameObject)); GameObject triggerXpArea = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/Prefabs/TriggerXpArea/TriggerXpArea.prefab", typeof(GameObject)); if (!aggro || !projector || !triggerXpArea) { Debug.LogError("No aggro or projector or triggerXpArea object"); return; } Instantiate(aggro, instantiatedTmp.transform); Instantiate(projector, instantiatedTmp.transform); Instantiate(triggerXpArea, instantiatedTmp.transform); PrefabUtility.ReplacePrefab(instantiatedTmp, tmp); DestroyImmediate(instantiatedTmp); DestroyImmediate(emptyGO); }
private void Awake() { m_AttackingAgent = GetComponent <AttackingUnit>(); m_NavMeshAgent = GetComponent <NavMeshAgent>(); m_Rigidbody = GetComponent <Rigidbody>(); }
public string FightUnit(IUnit FirstUnit, IUnit SecondUnit) { int UnitFlag = 1; string result = string.Empty; IUnit AttackingUnit; IUnit DefendingUnit; Random random = new Random(); int RandomForAttackingUnit = random.Next(1, 21); int RandomForDefendingUnit = random.Next(1, 21); if (RandomForAttackingUnit + FirstUnit.Initiative > RandomForDefendingUnit + SecondUnit.Initiative) { AttackingUnit = FirstUnit; DefendingUnit = SecondUnit; result += result += string.Format("{0} из вашей армии против {1} ", AttackingUnit.Name, DefendingUnit.Name); } else { AttackingUnit = SecondUnit; DefendingUnit = FirstUnit; UnitFlag = 2; result += result += string.Format("{0} из вражеской армии против {1} ", AttackingUnit.Name, DefendingUnit.Name); } bool DonaldTramp(IUnit Attacking, IUnit Defending) { int Rand = random.Next(1, 21); if (Rand + Attacking.Dexterity > Defending.Armor) { return(true); } return(false); } bool IsAlive = true; if (DonaldTramp(AttackingUnit, DefendingUnit)) { IsAlive = DefendingUnit.GetHit(AttackingUnit.Damage); result += string.Format("\nнаносит {0} урона противнику ", AttackingUnit.Damage); } else { result += "\nпромахивается по противнику "; } if (IsAlive) { if (DonaldTramp(DefendingUnit, AttackingUnit)) { IsAlive = AttackingUnit.GetHit(DefendingUnit.Damage); result += string.Format("\nпроитвник наносит {0} урона ", DefendingUnit.Damage); } else { result += "\nпротивник промахивается"; } } else { result += "противник убит"; } return(result); }