void Start() { fireEleAI = GetComponentInParent <FireElementalAI>(); skeletonAI = GetComponentInParent <SkeletonAI>(); enemyMage = GetComponentInParent <EnemyMage>(); bossBehaviour = GetComponentInParent <BossBehaviour>(); }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.CompareTag("Enemy")) //if the object is classified as enemy { Destroy(gameObject); SkeletonAI enemy = col.GetComponent <SkeletonAI>(); KnightAI enemy2 = col.GetComponent <KnightAI>(); BigBossAI enemy3 = col.GetComponent <BigBossAI>(); if (enemy != null) { enemy.TakeDamage(Damage); enemy.SetFlash(0.2f); } else if (enemy2 != null) { enemy2.TakeDamage(Damage); enemy2.SetFlash(0.2f); } else if (enemy3 != null) { Debug.Log("sdffsafsdfsdfsdfsdfsdfds"); enemy3.TakeDamage(Damage); enemy3.SetFlash(0.2f); } } else if (col.gameObject.CompareTag("Ground")) // just destroy the projectile if it hits the ground { Destroy(gameObject); } }
private void SpawnEnemy(GameObject enemy) { GameObject newEnemy = Instantiate(enemy); int index = Random.Range(0, spawnPoints.Length); newEnemy.transform.position = spawnPoints[index].position; SkeletonAI AI = newEnemy.GetComponent <SkeletonAI>(); EnemyStats stats = newEnemy.GetComponent <EnemyStats>(); AI.target = player; //determin the range of the skelton (stop them from just standing in a circle) AI.range = Random.Range(AI.meleeRange, AI.range); if (Random.value <= meleeChance) { AI.range = AI.meleeRange; } stats.health = stats.health * healthScaler; AI.agresstion = MaxAgression * (1 - (5 / (wave + 4))); if (enemy = pumkinBoss) { spawnBoss = false; AI.agresstion = MaxAgression * (1 - (1 / (wave))); BossSpawned?.Invoke(); } enemiesAlive++; enemiesToSpawn--; StartCoroutine(DelayNextSpawn()); }
void Start() { weaponCollider = transform.GetChild(0).GetChild(0).GetComponent <BoxCollider2D>(); enemy = GetComponentInParent <Enemy> (); skeletonAI = GetComponentInParent <SkeletonAI> (); enemyStats = transform.parent.transform.parent.GetChild(0).GetComponent <EnemyStats>(); }
void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.CompareTag("Enemy")) { player.GetComponent <PlayerMovement>().KnockbackCount = player.GetComponent <PlayerMovement>().KnockbackLength; //register the amount of knockback here if (col.transform.position.x < transform.position.x) { player.GetComponent <PlayerMovement>().KnockFromRight = false;//got hit from right } else { player.GetComponent <PlayerMovement>().KnockFromRight = true;//got hit from left } SkeletonAI enemy = col.GetComponent <SkeletonAI>(); KnightAI enemy2 = col.GetComponent <KnightAI>(); FireballProperties enemy3 = col.GetComponent <FireballProperties>(); if (enemy != null) { player.GetComponent <PlayerMovement>().TakeDamage(30); } else if (enemy2 != null) { player.GetComponent <PlayerMovement>().TakeDamage(15); } else if (enemy3 != null) { player.GetComponent <PlayerMovement>().TakeDamage(20); } } else if (col.gameObject.CompareTag("Ground")) { Debug.Log("This is the ground.Don't do anytthing"); } }
void InstantiateSkeleton(SkeletonAI.Team team) { SkeletonAI skeleton = Instantiate(skeletonAIPrefab, spawnPoint.transform.position, Quaternion.identity).GetComponent <SkeletonAI>(); skeleton.SetTeam(team); skeleton.SetStatsText(); StartBornFX(); GameManager.instance.allSkeletons.Add(skeleton); }
void Start() { skeletonAI = GetComponentInParent <SkeletonAI>(); weaponController = FindObjectOfType <WeaponController>(); playerStats = FindObjectOfType <PlayerStats>(); enemyBodyAnim = GetComponent <Animator>(); parent = transform.parent.gameObject; handsgameObject = parent.transform.GetChild(1).GetChild(0).gameObject; enemyHandsAnim = handsgameObject.GetComponent <Animator>(); }
IEnumerator Attack(Transform obj) { anim.SetBool("Walk", false); isAttacking = true; anim.SetBool("isAttacking", isAttacking); StopAgent(); if (obj.gameObject.tag == "Skeleton") { SkeletonAI skeleton = obj.GetComponent <SkeletonAI>(); while (skeleton.isDeath == false && HasTargetReached(skeleton.transform) == true) { anim.SetTrigger("Attack"); yield return(new WaitForSeconds(attackSpeed)); StartCoroutine(skeleton.HitDamage(currentDamage)); } } else if (obj.gameObject.tag == "Player") { PlayerController player = obj.GetComponent <PlayerController>(); while (player.isDeath == false && HasTargetReached(player.transform) == true) { anim.SetTrigger("Attack"); yield return(new WaitForSeconds(attackSpeed)); StartCoroutine(player.HitDamage(currentDamage)); } } else if (obj.gameObject.tag == "Opponent") { OpponentAI opponent = obj.GetComponent <OpponentAI>(); while (opponent.isDeath == false && HasTargetReached(opponent.transform) == true) { anim.SetTrigger("Attack"); yield return(new WaitForSeconds(attackSpeed)); StartCoroutine(opponent.HitDamage(currentDamage)); } } isAttacking = false; anim.SetBool("isAttacking", isAttacking); ReleaseAgent(); }
// Use this for initialization void Start() { enemyBody = GetComponent <Rigidbody2D>(); skeletonAI = GetComponentInParent <SkeletonAI> (); handsAnim = transform.GetChild(1).GetChild(0).GetComponent <Animator>(); body = transform.Find("Body S"); //rightHand = GameObject.Find ("Right Hand S"); rightHand = transform.GetChild(1).GetChild(0).GetChild(0).gameObject; //leftHand = GameObject.Find ("Left Hand S"); leftHand = transform.GetChild(1).GetChild(0).GetChild(1).gameObject; //weapon = GameObject.Find ("Skeleton Dagger"); weapon = transform.GetChild(1).GetChild(0).GetChild(0).GetChild(0).gameObject; }
private void CreateObject(string name, Vector3 position, Vector3 scale, Vector3 rotation, List <GameObject> areaList) { GameObject _object; _object = Instantiate(Resources.Load(name, typeof(GameObject))) as GameObject; _object.transform.position = position; _object.transform.localScale = scale; _object.transform.eulerAngles = rotation; if (_object.tag == "Enemy") { SkeletonAI skeletonAI = _object.GetComponent <SkeletonAI>(); skeletonAI.node1 = "RoamNode" + gameObject.name + "1(Clone)"; skeletonAI.node2 = "RoamNode" + gameObject.name + "2(Clone)"; skeletonAI.node3 = "RoamNode" + gameObject.name + "3(Clone)"; } areaList.Add(_object); }
SkeletonAI GetClosestSkeleton() { List <SkeletonAI> skeletons = GameManager.instance.allSkeletons.Where(a => a.team != team).ToList(); SkeletonAI bestTarget = null; float closestDistanceSqr = Mathf.Infinity; Vector3 currentPosition = transform.position; foreach (SkeletonAI potentialTarget in skeletons) { Vector3 directionToTarget = potentialTarget.transform.position - currentPosition; float dSqrToTarget = directionToTarget.sqrMagnitude; if (dSqrToTarget < closestDistanceSqr) { closestDistanceSqr = dSqrToTarget; bestTarget = potentialTarget; } } return(bestTarget); }
IEnumerator OnMouseRightClick(Transform target) { SkeletonAI selectedSkeleton = null; RaycastHit hit; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity)) { if (hit.transform.gameObject.tag == "Skeleton") { selectedSkeleton = hit.transform.GetComponent <SkeletonAI>(); } } if (selectedSkeleton == null) { yield return(null); } if (selectedSkeleton.isDeath == true || hasHealOnHands == false) { yield return(null); } if (hit.transform.gameObject.GetComponent <SkeletonAI>().team != SkeletonAI.Team.Player) { yield return(null); } anim.SetTrigger("HealIt"); isInteracting = true; yield return(new WaitForSeconds(AnimationDatas.instance.GetAnimationLength(AnimationDatas.AnimationStates.HealIt) / 2f)); GameObject fx = Instantiate(healFXObj.gameObject, transform.position, Quaternion.identity); fx.GetComponent <Projectile>().SetTarget(hit.transform, SkeletonAI.Team.Player, upgradeAmount); hasHealOnHands = false; isInteracting = false; }
SkeletonAI GetClosestFriendSkeleton() { SkeletonAI closestSkeleton = null; float closestDistance = Mathf.Infinity; if (HasAnyLiveSkeletons() == true) { foreach (var skeleton in GameManager.instance.allSkeletons) { if (skeleton.team != SkeletonAI.Team.Enemy) { continue; } if (Vector3.Distance(transform.position, skeleton.transform.position) <= closestDistance) { closestSkeleton = skeleton; } } } return(closestSkeleton); }
void Update() { //search for closest skeleton //if there is no skeleton than settarget necromancer //if it finds closest skeleton //than go to that skeleton //if that skeleton reached enemy //than attack it if (isDeath) { return; } LookAtCamera(txtStats.transform.parent); if (GameManager.instance.GameFinished) { StopAgent(); anim.SetBool("isAttacking", false); anim.SetBool("Walk", false); return; } SkeletonAI skeleton = GetClosestSkeleton(); if (skeleton == null || skeleton.isDeath == true) { SetTarget(necromancerTarget); if (HasTargetReached(necromancerTarget)) { if (necromancerTarget.tag == "Player") { if (necromancerTarget.GetComponent <PlayerController>().isDeath == false) { if (isAttacking == false) { StartCoroutine(Attack(necromancerTarget)); } } else { necromancerTarget = null; skeleton = null; } } else if (necromancerTarget.tag == "Opponent") { if (necromancerTarget.GetComponent <OpponentAI>().isDeath == false) { if (isAttacking == false) { StartCoroutine(Attack(necromancerTarget)); } } else { necromancerTarget = null; skeleton = null; } } } } else if (isAttacking == false && HasTargetReached(skeleton.transform) == true) { StartCoroutine(Attack(skeleton.transform)); } else if (isAttacking == false && skeleton.isDeath == false && HasTargetReached(skeleton.transform) == false) { SetTarget(skeleton.transform); } else { SetTarget(necromancerTarget); } if (isBorning == false && isAttacking == false) { anim.SetBool("Walk", true); if (agent != null && target != null) { agent.SetDestination(target.position); } } }