private void Spawn() { SetSpawnFill(); if (currentSpawnTimeInSeconds < spawnTimeInSeconds) { currentSpawnTimeInSeconds += Time.deltaTime; } else { if (limitAmountOfUnits && CheckForMaxUnits()) { return; } if (teamData.GetTeamBelonging() == Team.TeamRed) { if (CastleFightData.instance.IsMaxUnitsReached() || CheckIfUnitCapacityReached() || CastleFightData.instance.IsPauseSpawningUnits()) { return; } InstantiateUnit(); currentSpawnTimeInSeconds = 0f; } else { InstantiateUnit(); currentSpawnTimeInSeconds = 0f; } } }
private void OnTriggerEnter2D(Collider2D other) { if (abilityActivated == false || currentAbility.OnlyTargetSelf()) { return; } if (other.GetComponent <Health>()) { if (targetFriendlyUnits) { if ((other.GetComponent <TeamData>().GetTeamBelonging() == teamBelonging.GetTeamBelonging()) && other.GetComponent <Health>().IsUnit() && other.GetComponent <Health>().GetHp() > 0f) { if (!CheckIfTargetIsInList(other.GetComponent <Health>())) { AddTarget(other.GetComponent <Health>()); } } } else { if ((other.GetComponent <TeamData>().GetTeamBelonging() != teamBelonging.GetTeamBelonging()) && other.GetComponent <Health>().GetHp() > 0f) { if (!CheckIfTargetIsInList(other.GetComponent <Health>())) { AddTarget(other.GetComponent <Health>()); } } } } }
private void OnTriggerEnter2D(Collider2D other) { if ((other.tag == "NPC") && other.GetComponent <TeamData>()) { if (other.GetComponent <TeamData>().GetTeamBelonging() != teamData.GetTeamBelonging() && other.GetComponent <Health>().GetHp() > 0f) { AddTarget(other.GetComponent <Health>()); } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <Health>()) { if ((other.GetComponent <TeamData>().GetTeamBelonging() != teamBelonging.GetTeamBelonging()) && other.GetComponent <Health>().GetHp() > 0f) { if (!CheckIfTargetIsInList(other.GetComponent <Health>())) { AddTarget(other.GetComponent <Health>()); } } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <TeamData>()) { if (other.GetComponent <TeamData>().GetTeamBelonging() == teamData.GetTeamBelonging()) { return; } } if ((other != null) && (target != null) && (other.gameObject != gameObject)) { if (!hasAOE && other.gameObject == target.gameObject) { target.TakeDamage(projectileDamage); if (ability != null) { target.GetComponent <AbilitiesUsedOnTarget>().AddAbilityUsedOnTarget(ability); } if (target.GetComponent <Attacker>() && shooter != null) { target.GetComponent <Attacker>().CheckForAggro(shooter); } targetPosition = new Vector3(other.gameObject.transform.position.x, other.gameObject.transform.position.y, other.gameObject.transform.position.z); myAnimator.SetBool("hitTarget", true); } else if (hasAOE && isExploding) { if (other.tag == "NPC" || other.tag == "Building") { if (other.GetComponent <TeamData>().GetTeamBelonging() != teamData.GetTeamBelonging()) { other.GetComponent <Health>().TakeDamage(aoeDamage); } if (target.GetComponent <Attacker>() && shooter != null) { target.GetComponent <Attacker>().CheckForAggro(shooter); } } } /* * else * { * Debug.Log("Triggered: else statement"); * myAnimator.SetBool("hitTarget", true); * } */ } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <TeamData>()) { if (other.GetComponent <TeamData>().GetTeamBelonging() != teamData.GetTeamBelonging()) { triggered = true; if (spawningTrigger) { // Activate trigger unitSpawner.StartSpawning(); boxCollider.enabled = false; return; } if (trapTrigger) { enemyTrap.TriggerTrap(); boxCollider.enabled = false; } } } }
private void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <Health>()) { if (other.GetComponent <TeamData>().GetTeamBelonging() != team.GetTeamBelonging()) { mover.MoveTo(other.gameObject); } } }
// Update is called once per frame public virtual void Start() { teamBelonging = GetComponent <TeamData>(); mover = GetComponent <Mover>(); targets = new List <Health>(); myAnimator = GetComponent <Animator>(); circleCollider = GetComponentInChildren <CircleCollider2D>(); if (teamBelonging.GetTeamBelonging() == Team.TeamRed) { UnitUpgrades.instance.AddUpgradesToUnit(GetComponent <Health>()); AddToBaseDamage(GlobalUpgrades.instance.GetUpgradeValueOnUpgradesIndex(0)); // Index 0 is attackDamageUpgrade IncreaseCriticalChance(GlobalUpgrades.instance.GetUpgradeValueOnUpgradesIndex(2)); // Index 2 is CriticalChance IncreaseAttackSpeed(GlobalUpgrades.instance.GetUpgradeValueOnUpgradesIndex(3)); IncreaseCriticalDamageMultiplier(GlobalUpgrades.instance.GetUpgradeValueOnUpgradesIndex(4)); } }
private void InstantiateUnit(GameObject unitToSpawn) { GameObject instance = Instantiate(unitPrefab[indexInCurrentWave], transform); instance.transform.SetParent(gameObject.transform); if (instance.GetComponent <TeamData>()) { instance.GetComponent <TeamData>().SetTeamBelonging(teamData.GetTeamBelonging()); } if (instance.GetComponent <NPCcontroller>()) { instance.GetComponent <NPCcontroller>().SetWaypoints(waypointsList); } }
private void SetDwellingData(GameObject dwelling) { if (CastleFightData.instance.ReduceMoney(dwelling.GetComponent <DwellingScript>().GetBuyCost())) { GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f); GameObject instance = Instantiate(dwelling, gameObject.transform); if (instance.GetComponent <TeamData>()) { instance.GetComponent <TeamData>().SetTeamBelonging(teamData.GetTeamBelonging()); } if (instance.GetComponent <DwellingScript>()) { instance.GetComponent <DwellingScript>().SetDestroyOnZeroHealth(destroyOnZeroHealth); if (waypointsList.Length > 0) { instance.GetComponent <DwellingScript>().SetWaypoints(waypointsList); } else { instance.GetComponent <DwellingScript>().SetWaypoints(GetComponentInParent <DwellingScript>().GetWaypointsList()); } if (loopingWaypointsList.Length > 0) { if (loopingWaypointsList.Length > 0) { instance.GetComponent <DwellingScript>().SetLoopingWaypointsList(loopingWaypointsList); } else { instance.GetComponent <DwellingScript>().SetLoopingWaypointsList(GetComponentInParent <DwellingScript>().GetLoopingWaypointsList()); } } } //else if() instance.transform.SetParent(gameObject.transform.parent.parent); instance.transform.position = transform.parent.position; Destroy(parentObject); } else { CastleFightGui.instance.SetInfoText("Not enough money to buy dwelling!"); // Connect to UI element for info } }
// Start is called before the first frame update void Start() { mouseController = FindObjectOfType <TargetMouseSelected>(); myRigidbody = GetComponent <Rigidbody2D>(); myAnimator = GetComponent <Animator>(); selectable = GetComponent <Selectable>(); teamData = GetComponent <TeamData>(); unitParent = transform.parent.parent.GetChild(2).gameObject; health = GetComponent <Health>(); sellProfit = buyCost / 2; currentUnits = new Health[3]; if (teamData.GetTeamBelonging() == Team.TeamRed) { spawnTimeInSeconds -= GlobalUpgrades.instance.GetUpgradeValueOnUpgradesIndex(1); // Index 1 is spawnTimeUpgrade unitManager = FindObjectOfType <UnitManagerPanel>(); } if (dwellingUpgrader == null) { dwellingUpgrader = GetComponentInChildren <DwellingUpgrader>(); } }