void Awake() { enemyLogic = this.gameObject.GetComponent<EnemyLogic>(); enemyData = this.gameObject.GetComponent<EnemyData>(); playerData = GameObject.Find("Player").GetComponent<PlayerData>(); gameStateData = GameObject.Find("GameState").GetComponent<GameStateData>(); }
// Use this for initialization void Start() { BossHealthBarInitialLength = Screen.width * 85 / 100; BossLogic = (EnemyLogic)BossObject.gameObject.GetComponent(typeof(EnemyLogic)); BossMaxHealth = BossLogic.MaxHealth; BossCurrentHealth = BossMaxHealth; }
private void OnTriggerEnter(Collider other) { if (other.tag == "HurtBox") { if (other.gameObject.layer == 10) //if hurtbox is on enemy layer { EnemyLogic enemy = other.GetComponentInParent <EnemyLogic>(); if (enemy.currentAttack.getAttacking() && enemy.currentAttack.getCanHurt()) { PlayerManager.Instance.currentHealth -= enemy.currentAttack.damage; Vector3 direction = transform.position - other.transform.root.position; direction.y = 100.0f; direction *= 5.0f * enemy.currentAttack.knockbackMult; float time = 0.2f; object[] array = { direction, time }; SendMessage("PlayerKnockback", array); } } else if (other.gameObject.layer == 11) //if hurtbox is on enemyProjectile layer { ProjectileInfo projectile = other.GetComponentInParent <ProjectileInfo>(); PlayerManager.Instance.currentHealth -= projectile.damage; Vector3 direction = transform.position - other.transform.root.position; direction.y = 100.0f; direction *= 5.0f * projectile.knockbackMult; float time = 0.2f; object[] array = { direction, time }; SendMessage("PlayerKnockback", array); } } }
private void Start() { LoadResources resources = new LoadResources(); resources.Initialize(); //アクターの作成とメンバーの追加 ActorDataModel actorData = ActorDataModel.Instance; MemberDataModel memberData = MemberDataModel.Instance; memberData.Add(ActorLogic.Create("Mandrake", 3)); memberData.Add(ActorLogic.Create("Slime", 3)); memberData.Add(ActorLogic.Create("MechanicSoldier", 3)); memberData.Add(ActorLogic.Create("Kyubi", 3)); //エネミーの作成 EnemyDataModel enemyData = EnemyDataModel.Instance; enemyData.Initialize(); enemyData.Add(EnemyLogic.Create("Goblin", 3)); enemyData.Add(EnemyLogic.Create("GreenDragon", 3)); enemyData.Add(EnemyLogic.Create("Goblin", 4)); //アイテム InventoryDataModel.GetInstance().StartUp(); var manager = gameObject.GetComponent <BattleManager>(); manager.Initialize(); }
/// <summary> /// バトル開始 /// </summary> /// <returns></returns> public static AsyncSubject <List <LootItemStruct> > BootBattle() { AsyncSubject <List <LootItemStruct> > subject = new AsyncSubject <List <LootItemStruct> >(); var dungeon = DungeonDictionary.GetDungeonMapData(DungeonDataModel.Instance.DungeonId); var enemies = BattleLogic.EnemiesChoice(); var enemyDataModel = EnemyDataModel.Instance; enemyDataModel.Initialize(); enemies.Enemies.ForEach(enemyId => { float level = Random.Range(dungeon.enemyLevel.min, dungeon.enemyLevel.max); level = level * DungeonDataModel.Instance.Location.y + 1; level += enemies.AddLevel; enemyDataModel.Add(EnemyLogic.Create(enemyId, (int)level)); }); _battleScene = Object.Instantiate((GameObject)Resources.Load("Prefabs/Scene/Battle"), Vector3.zero, Quaternion.identity); _battleScene.transform.Find("FrontCanvas").GetComponent <Canvas>().worldCamera = GameObject.Find("MainCamera").GetComponent <Camera>(); var battleManager = _battleScene.transform.Find("System").GetComponent <BattleManager>(); battleManager.Initialize(); battleManager.EndBattle.Subscribe(loots => { subject.OnNext(loots); subject.OnCompleted(); }); return(subject); }
private void Start() { gameManager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>(); numEnemySpawns = Random.Range(gameManager.minEnemies, gameManager.maxEnemies); enemyList = gameManager.enemyList; triggered = false; enemySpawnerNull = GameObject.FindGameObjectWithTag("EnemySpawnNull"); for (int i = 0; numEnemySpawns > i; i++) { Vector3 pos = new Vector3(transform.position.x + Random.Range(-4f, 4f), 2, transform.position.z + Random.Range(-4f, 4f)); Transform thisEnemy = Instantiate(enemyPrefab.transform, pos, Quaternion.identity, enemySpawnerNull.transform); gameManager.enemyList.Add(thisEnemy); myEnemys.Add(thisEnemy); EnemyLogic thisEnemyLogic = thisEnemy.GetComponent <EnemyLogic>(); thisEnemyLogic.id = enemyList.Count + 1; thisEnemyLogic.health = Random.Range(1.0f, 100f); thisEnemyLogic.damage = Random.Range(1.0f, 3f); thisEnemyLogic.movementSpeed = Random.Range(2f, 7f); thisEnemyLogic.attackSpeed = Random.Range(1.0f, 3f); } }
public ActionResult Combat() { User user = (User)Session["user"]; Enemy enemy = new Enemy(); UserLogic userLogic = new UserLogic(); EnemyLogic enemyLogic = new EnemyLogic(); Combat combat = new Combat(); //random nummer waarmee de enemy wordt bepaald int number = enemyLogic.RandomNumber(); //enemy ophalen uit de database enemy = combat.GetNewEnemy(number); //de stats van de enemy aanpassen gebaseerd op de user z'n level enemy = enemyLogic.EnemyBalance(user.Level, enemy); user.HalfHp = userLogic.GetHalfHp(user.MaxHp); user.LowHp = userLogic.GetLowHp(user.MaxHp); enemy.HalfHp = enemyLogic.GetHalfHp(enemy.MaxHp); enemy.LowHp = enemyLogic.GetLowHp(enemy.MaxHp); Session["enemy"] = enemy; return(RedirectToAction("Index", "Combat")); }
public Enemy startupBasicEnemy(Point dimensions, AnimationData animationData, int score, int zLayer) { base.startupAnimatedGameObject(dimensions, animationData, zLayer, false); enemyLogic = new EnemyLogic(this.basicEnemyLogic); this._collisionName = CollisionIdentifiers.ENEMY; this.score = score; return(this); }
void Start() { animator = GetComponent<Animator>(); motor = GetComponent<EnemyMotor>(); logic = GetComponent<EnemyLogic>(); animator.SetBool("Jumping",false); animator.SetLayerWeight(1,1); }
void OnParticleCollision(GameObject other) { print("ice hit"); if (other.tag == "Enemy") { EnemyLogic enemyLogic = other.GetComponent <EnemyLogic>(); enemyLogic.health -= damage; } }
void Start() { Rigidbody pb_rigidbody = GetComponent <Rigidbody>(); m_enemyLogic = FindObjectOfType <EnemyLogic>(); if (pb_rigidbody) { pb_rigidbody.velocity = transform.forward * PlayerBulletSpeed; } }
public void OnTriggerStay2D(Collider2D collision) { if (collision.tag == "Enemy") { //Debug.Log("Collider"); EnemyInside = true; EnemyHealth = collision.GetComponent <EnemyLogic>(); } if (collision.tag == "Chest") { collision.GetComponent <ChestOpen>().OpenChest(); } }
// Update is called once per frame private void OnTriggerEnter(Collider other) { if (other.tag == "Target") { Destroy(other.gameObject); Destroy(this.gameObject); } else if (other.tag == "Enemy") { EnemyLogic enemy = other.gameObject.GetComponent <EnemyLogic>(); enemy.takeDamage(10); Destroy(this.gameObject); } }
public void AddEnemy() { Vector3 pos = new Vector3(transform.position.x + Random.Range(-4f, 4f), 2, transform.position.z); Transform thisEnemy = Instantiate(enemyPrefab, pos, Quaternion.identity); thisEnemy.name = "Enemy " + enemyList.Count.ToString(); enemyList.Add(thisEnemy); EnemyLogic thisEnemyLogic = thisEnemy.GetComponent <EnemyLogic>(); thisEnemyLogic.id = enemyList.Count + 1; thisEnemyLogic.health = Random.Range(1.0f, 100f); thisEnemyLogic.damage = Random.Range(1.0f, 3f); thisEnemyLogic.movementSpeed = Random.Range(2f, 7f); thisEnemyLogic.attackSpeed = Random.Range(1.0f, 3f); }
private IEnumerator Shoot() { isShooting = true; anim.SetBool("IsFiring", true); anim.SetTrigger("Fire"); GunShoot.volume = UnityEngine.Random.Range(0.5f, 0.7f); GunShoot.PlayOneShot(GunShoot.clip); RaycastHit2D hitInfo = Physics2D.Raycast(ShootPoint.position, -ShootPoint.right + new Vector3(0, UnityEngine.Random.Range(-TakedGunChar.WeaponRecoil, TakedGunChar.WeaponRecoil), 0)); GameObject ShootEffect = Instantiate(ShootEffects[UnityEngine.Random.Range(0, ShootEffects.Length)], ShootPoint.parent.transform); ShootEffect.transform.localPosition = new Vector3(ShootPoint.transform.localPosition.x, ShootPoint.transform.localPosition.y, ShootPoint.transform.localPosition.z + 0.1f); if (Mathf.Approximately(ShootPoint.parent.transform.eulerAngles.y, 180)) { ShootEffect.transform.eulerAngles = new Vector3(0, 0, 180); } GameObject Blood = new GameObject(); if (hitInfo) { if (hitInfo.transform.tag == "Enemy") { EnemyLogic enemy = hitInfo.transform.GetComponent <EnemyLogic>(); Blood = Instantiate(BloodSprites[UnityEngine.Random.Range(0, BloodSprites.Length)], hitInfo.point, Quaternion.identity); Blood.transform.localScale = new Vector3(UnityEngine.Random.Range(0f, 2f), UnityEngine.Random.Range(0f, 2f)); enemy.GetDamage(TakedGunChar.Damage); } LineRenderer.SetPosition(0, ShootPoint.position); LineRenderer.SetPosition(1, hitInfo.point); } else { LineRenderer.SetPosition(0, ShootPoint.position); LineRenderer.SetPosition(1, -ShootPoint.right * 100); } LineRenderer.enabled = true; yield return(new WaitForSeconds(0.02f)); Destroy(ShootEffect); Destroy(Blood.gameObject); LineRenderer.enabled = false; yield return(new WaitForSeconds(60f / TakedGunChar.ShotsPerMinute)); isShooting = false; }
private void OnSceneGUI() { eLogic = (EnemyLogic)target; var positions = eLogic.path; if (positions != null && positions.Length > 1) { TileGrid grid = GameObject.FindObjectOfType <TileGrid>(); Handles.color = Color.red; float dirX = positions[1].x - positions[0].x; float dirY = positions[1].y - positions[0].y; float thickness = 0.2f; Vector2 dir = (Mathf.Abs(dirX) > Mathf.Abs(dirY)) ? new Vector2(Mathf.Sign(dirX), 0) : new Vector2(0, Mathf.Sign(dirY)); Vector3[] points = new Vector3[3]; points[0] = positions[0] - (Vector2.one * 0.5f) + (dir * 0.5f); points[1] = positions[0] - (Vector2.one * 0.5f) + (new Vector2(dir.y, dir.x) * thickness) + (dir * 0.06f); points[2] = positions[0] - (Vector2.one * 0.5f) + (new Vector2(-dir.y, -dir.x) * thickness) + (dir * 0.06f); Handles.DrawSolidDisc(positions[0] - (Vector2.one * 0.5f), Vector3.back, thickness); Handles.DrawAAConvexPolygon(points); Handles.color = Color.cyan; for (int i = 1; i < positions.Length + 1; i++) { var previousPoint = positions[i - 1]; var currentPoint = positions[i % positions.Length]; Handles.DrawDottedLine(previousPoint - (Vector2.one * 0.5f), currentPoint - (Vector2.one * 0.5f), 4f); positions[i - 1] = Handles.PositionHandle(positions[i - 1] - (Vector2.one * 0.5f), Quaternion.identity) + (Vector3.one * 0.5f); positions[i - 1].x = (float)Mathf.RoundToInt(positions[i - 1].x); positions[i - 1].y = (float)Mathf.RoundToInt(positions[i - 1].y); } } }
/// <summary> /// Создать представление врага. /// </summary> /// <param name="enemy">Логика создаваемого врага.</param> public void InstantiateEnemy(EnemyLogic enemy) { GameObject prefab = null; switch (enemy.Model.Type) { case EnemyType.Small: prefab = GameModel.Instance.GameSettings.SmallEnemyPrefab; break; case EnemyType.Medium: prefab = GameModel.Instance.GameSettings.MediumEnemyPrefab; break; case EnemyType.Large: prefab = GameModel.Instance.GameSettings.LargeEnemyPrefab; break; default: throw new NotSupportedException(); } if (prefab == null) { Debug.LogWarning("Prefab for this kind of enemy is not specified."); return; } var instance = Instantiate(prefab, transform); var enemyView = instance.GetComponent <EnemyView>(); if (enemyView != null) { enemyView.Logic = enemy; } else { Debug.LogWarning("Enemy view must have behaviour of EnemyView class."); } }
void FixedUpdate() { if (m_gameController.M_GameLogic.M_SpawnerLogics.Count > 0 && m_gameController.M_GameLogic.M_EnemyLogics.Count < m_gameController.M_GameLogic.M_MaximumEnemiesNumber && m_timer >= timeBetweenSpawn) { m_timer = 0.0f; //Randomly choose a spawner System.Random rnd = new System.Random(); Vector3 spawnPosition = m_gameController.M_GameLogic.M_SpawnerLogics[rnd.Next(0, m_gameController.M_GameLogic.M_SpawnerLogics.Count)].M_Position; //Adding an enemy EnemyLogic enemyLogic = new EnemyLogic(spawnPosition, m_gameController.M_GameLogic.FindCubeByPosition(spawnPosition)); m_gameController.M_GameLogic.M_EnemyLogics.Add(enemyLogic); Collider[] colliders = Physics.OverlapSphere(spawnPosition, 1f); if (colliders.Length == 1) { if (colliders[0].gameObject.tag == "LevelBlock") { GameObject currentEnemyCube = colliders[0].gameObject; m_enemy = Instantiate(Resources.Load("enemy"), spawnPosition, Quaternion.identity) as GameObject; m_enemy.GetComponent <EnemyController>().Initialize(enemyLogic, currentEnemyCube); } } } }
public void PrepareLevel(Block b) { current_block = b; // get difficulty -- between 8 (easiest) and 16 (latest) int difficulty = GetLeadingZeros(b); // play audio if (difficulty < 12) { source.clip = clip1; } else { source.clip = clip2; } // place player Vector3 mPos = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)); mPos.x -= 10 * size - (size / 2); mPos.y += 10 * size - (size / 2); player.transform.position = new Vector3(mPos.x, mPos.y); GameObject.Find("player").GetComponent <MiniGameMoveLogic> ().pos = player.transform.position; // set boundaries Vector3 p = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)); lower_bound = p.y + size; right_bound = p.x - size; p.x -= 10 * size; p.y += 10 * size; upper_bound = p.y - size; left_bound = p.x + size; // update hud MiniGameHUDManager hud_manager = GameObject.Find("MiniGameHUDManager").GetComponent <MiniGameHUDManager> (); hud_manager.SetHUD(b); // setup board Image current = board.GetComponent <Image>(); //SpriteRenderer current = board.GetComponentInChildren<SpriteRenderer>(); ExhibitGenerator eg = new ExhibitGenerator(); current.sprite = eg.GenerateArt(b); // place board for any aspect ratio Vector3 board_position = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)); board_position.y += 35; board.transform.position = new Vector3(board_position.x, board_position.y); float aspect = (float)Screen.width / (float)Screen.height; Debug.Log("aspect: " + aspect); // 16:9 or wider if (aspect > 1.7f) { RectTransform vitals = hud_vitals.GetComponent <RectTransform> (); vitals.anchoredPosition = new Vector2(-0.56f, -2.981705f); vitals.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 919.13f); vitals.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 258.28f); RectTransform block = hud_block.GetComponent <RectTransform> (); block.anchoredPosition = new Vector2(1.98f, 0.0f); block.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 50.11f); block.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 42.43f); } else if (aspect <= 1.7f && aspect > 1.5f) { //around 16:10 RectTransform rt = hud_vitals.GetComponent <RectTransform> (); rt.anchoredPosition = new Vector2(-0.56f, -2.981705f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 771.7f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 250.78f); RectTransform block = hud_block.GetComponent <RectTransform> (); block.anchoredPosition = new Vector2(3.98f, 0.0f); block.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 46.14f); block.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 40.59f); } else { // yikes bitcoin.SetActive(false); hud_block.SetActive(false); RectTransform rt; rt = hud_vitals.GetComponent <RectTransform> (); rt.anchoredPosition = new Vector2(3.13f, -2.981705f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 771.7f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 250.78f); rt = heart.GetComponent <RectTransform> (); rt.anchoredPosition = new Vector2(232.0f, 42.0f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100.0f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100.0f); rt = freeze_blast.GetComponent <RectTransform> (); rt.anchoredPosition = new Vector2(142.0f, -29.8f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100.0f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100.0f); rt = armor.GetComponent <RectTransform> (); rt.anchoredPosition = new Vector2(-439.5f, -73.55f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100.0f); rt.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100.0f); armor_slider.SetActive(false); armor_text.SetActive(true); } // debug // grid = eg.GenerateGrid(b); // PrintGrid (grid); // place coins Random.InitState(b.height); // list of taken points List <int[]> points = new List <int[]> (); // add player starting point points.Add(new int[] { 9, 9 }); points.Add(new int[] { 8, 9 }); points.Add(new int[] { 7, 9 }); int n_coins = (int)Mathf.Floor(Random.Range(difficulty / 4, difficulty / 2)); for (int i = 0; i < n_coins; i++) { GameObject new_coin = Instantiate(coin, new Vector3(0.0f, 0.0f), Quaternion.identity); new_coin.transform.localScale = new Vector3(15.0f, 15.0f); new_coin.transform.parent = coin_holder.transform; int row = 0; int col = 0; // find an unoccupied area of the board do { row = (int)Mathf.Floor(Random.Range(0.0f, 10.0f)); col = (int)Mathf.Floor(Random.Range(0.0f, 10.0f)); } while (isCoinPlacementCollision(row, col, points)); points.Add(new int[] { col, row }); // set coin position Vector3 cpos = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)); cpos.x -= (col + 1) * size - (size / 2); cpos.y += (row + 1) * size - (size / 2); new_coin.transform.position = new Vector3(cpos.x, cpos.y); } // place enemies int n_enemies = (int)Mathf.Floor(Random.Range(difficulty / 4, difficulty / 3)); for (int i = 0; i < n_enemies; i++) { GameObject new_enemy = Instantiate(enemy, new Vector3(0.0f, 0.0f), Quaternion.identity); new_enemy.transform.localScale = new Vector3(15.0f, 15.0f); new_enemy.transform.parent = enemy_holder.transform; int row = 0; int col = 0; // find an unoccupied area of the board do { row = (int)Mathf.Floor(Random.Range(0.0f, 10.0f)); col = (int)Mathf.Floor(Random.Range(0.0f, 10.0f)); } while (isCoinPlacementCollision(row, col, points)); Debug.Log("row: " + row + " col: " + col); points.Add(new int[] { col, row }); // set enemy attributes new_enemy.SetActive(true); EnemyLogic el = new_enemy.GetComponent <EnemyLogic> (); el.upper_bound = upper_bound; el.lower_bound = lower_bound; el.right_bound = right_bound; el.left_bound = left_bound; el.speed = 20.0f + Mathf.Floor(Random.Range(0.0f, difficulty / 8.0f)); // set how powerful the enemy is based on the difficulty of the block if (difficulty <= 8) { el.savage_level = Random.Range(0.0f, 20.0f); el.wander_level = Random.Range(10.0f, 50.0f); } else if (difficulty < 12) { el.savage_level = Random.Range(20.0f, 60.0f); el.wander_level = Random.Range(30.0f, 80.0f); } else if (difficulty < 16) { el.savage_level = Random.Range(50.0f, 90.0f); el.wander_level = Random.Range(50.0f, 100.0f); } else { el.savage_level = Random.Range(80.0f, 100.0f); el.wander_level = Random.Range(70.0f, 100.0f); } // set enemy position Vector3 epos = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, 0)); epos.x -= (col + 1) * size - (size / 2); epos.y += (row + 1) * size - (size / 2); new_enemy.transform.position = new Vector3(epos.x, epos.y); } in_mini_game = true; }
void Update() { if (partyLeader == true) { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector2 verticalComponent = ((Vector2)transform.up) * moveVertical; Vector2 horizontalComponent = ((Vector2)transform.right) * moveHorizontal; Vector2 calculatedVelocity = verticalComponent + horizontalComponent; my2DRigidbody.velocity = calculatedVelocity * moveSpeed; weaponCoolDownInSeconds = Mathf.Max(0, weaponCoolDownInSeconds - Time.deltaTime); rangedCoolDownInSeconds = Mathf.Max(0, rangedCoolDownInSeconds - Time.deltaTime); if (Input.GetMouseButtonDown(0) && weaponCoolDownInSeconds == 0) { FireAttack(); weaponCoolDownInSeconds = weaponCoolDownInSecondsDefault; } if (Input.GetMouseButtonDown(1) && rangedCoolDownInSeconds == 0) { FireRangedAttack(); rangedCoolDownInSeconds = rangedCoolDownInSecondsDefault; } //Rotate Screen if (Input.GetKey("q")) { rotationVariable = rotationVariable + (rotationSpeed); if (rotationVariable > 360) { rotationVariable = rotationVariable - 360; } transform.rotation = Quaternion.Euler(0, 0, rotationVariable); } if (Input.GetKey("e")) { rotationVariable = rotationVariable - (rotationSpeed); if (rotationVariable < 0) { rotationVariable = rotationVariable + 360; } transform.rotation = Quaternion.Euler(0, 0, rotationVariable); } } else { //applies to allies } foreach (AllyLogic ally in AllyLogics) { if (ally != this) { EnemyLogic closestEnemy = null; float absNearest = -1; foreach (EnemyLogic enemyLogic in EnemyLogic.enemyLogics) { float nearest = Vector2.Distance(transform.position, enemyLogic.transform.position); if (absNearest == -1 || nearest < absNearest) { absNearest = nearest; closestEnemy = enemyLogic; } } if ((closestEnemy == null) || Vector2.Distance(transform.position, closestEnemy.transform.position) > aggroRange) { if ((ally != this && (Vector2.Distance(GetPartyLeader().transform.position, transform.position) > repulsionDistance))) { Vector2 forceTowardLeader = GetPartyLeader().transform.position - transform.position; my2DRigidbody.velocity = forceTowardLeader; } } else if ((closestEnemy != null) && this != GetPartyLeader()) { Vector2 forceTowardEnemy = closestEnemy.transform.position - transform.position; my2DRigidbody.velocity = forceTowardEnemy; if (Vector2.Distance(GetPartyLeader().transform.position, transform.position) < meleeRange) { if (weaponCoolDownInSeconds <= 0) { weaponCoolDownInSeconds = weaponCoolDownInSecondsDefault * 2; //gather offsets to determine the spawn location of the enemy's attack float offset = 1; Vector2 spawnOffset = ((Vector2)closestEnemy.transform.position - (Vector2)transform.position).normalized * offset; Vector3 spawnLocation = transform.position + (Vector3)spawnOffset; spawnLocation.z = weaponAttack.transform.position.z; //rotate the attack towards the player Vector2 direction = spawnLocation - transform.position; float rotation = Mathf.Rad2Deg * (Mathf.Atan(direction.y / direction.x)); rotation += -90; if (direction.x < 0) { rotation += 180; } GameObject child = Instantiate(weaponAttack.gameObject, spawnLocation, Quaternion.Euler(0, 0, rotation)); child.transform.SetParent(transform); } weaponCoolDownInSeconds = Mathf.Max(0, weaponCoolDownInSeconds - Time.deltaTime); } else { if (rangedCoolDownInSeconds <= 0) { rangedCoolDownInSeconds = rangedCoolDownInSecondsDefault * 2; //gather offsets to determine the spawn location of the enemy's attack float offset = 1; Vector2 spawnOffset = ((Vector2)closestEnemy.transform.position - (Vector2)transform.position).normalized * offset; Vector3 spawnLocation = transform.position + (Vector3)spawnOffset; spawnLocation.z = weaponAttack.transform.position.z; //rotate the attack towards the enemy Vector2 direction = spawnLocation - transform.position; float rotation = Mathf.Rad2Deg * (Mathf.Atan(direction.y / direction.x)); rotation += -90; if (direction.x < 0) { rotation += 180; } GameObject childInstance = Instantiate(rangedAttack.gameObject, spawnLocation, Quaternion.Euler(0, 0, rotation)); childInstance.GetComponent <Rigidbody2D>().velocity = rangedAttack.speed * direction.normalized; } rangedCoolDownInSeconds = Mathf.Max(0, rangedCoolDownInSeconds - Time.deltaTime); } } if ((ally != this && (Vector2.Distance(ally.transform.position, transform.position) < repulsionForceRange))) { Vector2 difference = ally.transform.position - transform.position; float force = (-MaxRepulsionForce / aggroRange) * Vector2.Distance(ally.transform.position, transform.position) + MaxRepulsionForce; my2DRigidbody.AddForce(-force * difference.normalized); } } } }
public void RemoveEnemy(EnemyLogic enemy) { enemyLogics.Remove(enemy); }
public void AddEnemy(EnemyLogic enemy) { enemyLogics.Add(enemy); }
void Start() { m_enemyLogic = FindObjectOfType <EnemyLogic>(); HPStrip.value = HPStrip.maxValue = MAX_HP; //初始化血条 }
// Use this for initialization void Start() { spriteRenderer = GetComponent <SpriteRenderer>(); enemyLogicRef = GetComponent <EnemyLogic>(); }
private void Awake() { enemyMovement = new EnemyMovement(this, movementChangeFactor); enemyLogic = new EnemyLogic(enemyMovement, loseLayer, directionSwapLayerLeft, directionSwapLayerRight); }
/// <summary> /// Создать врага. /// </summary> /// <param name="enemy">Логика создаваемого врага.</param> public void AddEnemy(EnemyLogic enemy) { Field.InstantiateEnemy(enemy); }
void Start() { m_enemyLogic = FindObjectOfType <EnemyLogic>(); m_playerLogic = FindObjectOfType <PlayerLogic>(); }
public override void shutdown() { base.shutdown(); enemyLogic = null; }