private void OnCollisionEnter2D(Collision2D other) { if (uiText.text != null || uiText.text == "") { if (other.gameObject.CompareTag("Maze")) { if (wallPhaseTimer <= 0) { lives--; transform.position = this.spawnPoint; } else { Physics2D.IgnoreCollision(other.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>()); } } else if (other.gameObject.CompareTag("Enemy")) { Enemy enemy = other.gameObject.GetComponent <Enemy>(); enemy.SetTarget(this.gameObject); this.SetLives(this.GetLives() - 1); Vector3 displacement = other.gameObject.transform.position - transform.position; displacement = displacement.normalized; displacement *= -1; enemy.gameObject.GetComponent <Rigidbody2D>().AddRelativeForce(displacement, ForceMode2D.Force); enemy.SetTarget(null); } } else { Physics2D.IgnoreCollision(other.gameObject.GetComponent <Collider2D>(), GetComponent <Collider2D>()); } }
void Spawn() { //Debug.Log(enemies.Count); if (enemies.Count >= MaxEnemiesCount) { return; } enemyNo++; float randomXOffset = Random.Range(MinOffsetFromPlayer, MaxOffsetFromPlayer); bool randomBool = (Random.value < 0.5); if (randomBool) { randomXOffset *= -1; } float posX = world.player.transform.position.x + randomXOffset; float minPosY = world.groundMinY; float maxPosY = world.groundMaxY; float posY = Random.Range(minPosY, maxPosY); Vector3 spawnPosition = new Vector3(posX, posY, 0); Enemy newEnemy = Instantiate(enemyPrefab, spawnPosition, Quaternion.identity).GetComponent <Enemy>(); newEnemy.SetTarget(world.player); newEnemy.gameObject.name = "Enemy" + enemyNo.ToString(); newEnemy.transform.parent = world.transform; enemies.Add(newEnemy); world.AddObject(newEnemy.gameObject); }
void InitGame() { phase = Phase.SETUP; levelImage = GameObject.Find("LevelImage"); levelText = GameObject.Find("LevelText").GetComponent <Text>(); levelText.text = "Level " + level; levelImage.SetActive(true); Invoke("HideLevelImage", levelStartDelay); turnText = GameObject.Find("TurnText").GetComponent <Text>(); turnText.text = "Turn: " + turn; enemies.Clear(); player = GameObject.FindGameObjectWithTag("Player"); // Add all current enemies to the list of tracked enemies in the scene. GameObject[] enemyObjects = GameObject.FindGameObjectsWithTag("Enemy"); foreach (GameObject enemyObject in enemyObjects) { Enemy enemy = enemyObject.GetComponent <Enemy>(); enemy.SetTarget(player); enemies.Add(enemyObject.GetComponent <Enemy>()); } //boardScript.SetupScene(level); ChangePhase(); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player") { enemy.SetTarget(other.gameObject.GetComponent <Unit>()); } }
public void Fire(Enemy pEnemy) { pEnemy.transform.position = this.transform.position; pEnemy.SetTarget(m_FirePoint.position); pEnemy.Fly(); }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { parent.SetTarget(collision.GetComponent <Character>()); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.CompareTag("Player")) { Owner.SetTarget(collision.transform); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") { parent.SetTarget(collision.transform); } }
void createEnemy() { if (CountEnemy > 4) { return; } //end game if (GameManger.isGameOver) { return; } // 1. Ramdom point init enemy // 2. Instantiate to clone enemy from prefabs // 3. set target for enemy //1 int index = Random.Range(0, _pRandomEnemy.Length); Transform p = _pRandomEnemy[index]; //2 GameObject enemyObject = Instantiate(_prefEnemy, p.position, Quaternion.identity); //3 Enemy e = enemyObject.GetComponent <Enemy> (); e.SetTarget(_player); }
// Update is called once per frame void Update() { nextWaveTime -= Time.deltaTime; if (nextWaveTime < 0) { nextWaveTime = intervelTime; bool finised = true; //This wave Enemy Comes foreach (WaveComponent wc in wave) { if (wc.shooted < wc.num) { //shoot it, enenmyPrefab is a prefab object finised = false; wc.shooted++; GameObject enemyGO = Instantiate(wc.enenmyPrefab, this.transform.position, this.transform.rotation * Quaternion.Euler(-90f, 0f, 0f)) as GameObject; Enemy b = enemyGO.GetComponent <Enemy>(); b.SetTarget(sourcePlanet); break; } } if (finised == true) { Destroy(gameObject); //or Instantiate the next wave enemy } } }
///For Enemy Sight Collider (detect pLayer) private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "Player") //checks if tag is player then mark it as target { parent.SetTarget(collision.transform); } }
private void SpawnEnemy() { Enemy enemy = Instantiate(enemyPrefab).GetComponent <Enemy>(); enemy.gameObject.SetActive(true); enemy.SetTarget(_playerAvatar.transform); }
void Sight() { //일정 반경내의 플레이어 콜라이더 검출 Collider[] t_cols = Physics.OverlapSphere(transform.position, m_distance, m_layerMask); //안에 있다면 if (t_cols.Length > 0) { Transform t_tfPlayer = t_cols[0].transform; Vector3 t_direction = (t_tfPlayer.position - transform.position).normalized; float t_angle = Vector3.Angle(t_direction, transform.forward); //서로의 시야가 시야각에 들었다면 if (t_angle < m_angle * 0.5f) { if (Physics.Raycast(transform.position, t_direction, out RaycastHit t_hit, m_distance)) { //Lay에 닿은게 Player라면 장애물 없음! if (t_hit.transform.tag == "Player") { transform.position = Vector3.Lerp(transform.position, t_hit.transform.position, 0.01f); m_enemy.SetTarget(t_tfPlayer); } } } else { m_enemy.RemoveTarget(); } } }
IEnumerator Start() { yield return(new WaitForSeconds(secondsBeforeStart)); foreach (EnemyInfo enemy in enemies) { for (int i = 0; i < enemy.number; i++) { Transform spawnpoint = spawnpoints[Random.Range(0, spawnpoints.Length)]; Enemy e = Instantiate(enemy.enemy, spawnpoint.position, enemy.enemy.transform.rotation); e.ModifyMovementSpeed(enemy.movementSpeed); e.SetTarget(target); e.OnDeath += E_OnDeath; aliveEnemies.Add(e); yield return(new WaitForSeconds(enemy.timeUntilNextEnemy)); } } yield return(new WaitUntil(() => aliveEnemies.Count == 0)); Time.timeScale = victoryTimeScale; victoryScreen.SetActive(true); PlayerMovement.Instance.enabled = false; PlayerMovement.Instance.RB.velocity = Vector3.zero; PlayerMovement.Instance.Animator.SetFloat("Magnitude", 0); PlayerMovement.Instance.Animator.SetBool("IsShooting", false); yield return(new WaitForSeconds(victoryTime * victoryTimeScale)); SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex); }
// Spawns a single random enemy in a random spot void Spawn() { int randEnemy = Random.Range(0, enemyPrefabs.Count); int randLocation = Random.Range(0, spawnPoints.Count); Enemy enemy = Instantiate(enemyPrefabs[randEnemy], spawnPoints[randLocation].position, Quaternion.identity).GetComponent <Enemy>(); enemy.SetTarget(player.transform); }
public void Enter(Enemy e) { enemy = e; enemy.SetTarget(Enemy.TargetType.Player); enemy.ChangeAnimation(Enemy.AnimationState.Move); }
/// <summary> /// Détection d'entrée en collision /// </summary> /// <param name="collision">L'objet de collision</param> private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { // Définit la cible enemyScript.SetTarget(collision.transform); } }
void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { GetComponent <BoxCollider2D>().size = new Vector2(9f, 4f); enemy.SetTarget(other.gameObject); } }
/// <summary> /// Détection d'entrée en collision /// </summary> /// <param name="collision">L'objet de collision</param> private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Player")) { // Définit la cible enemyScript.SetTarget(collision.GetComponent <Character>()); } }
private void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.tag == "Player") { Debug.Log("Entering enemy Range"); parentObj.SetTarget(col.transform); } }
void CreateEnemy(Vector3 enemyPos, GameObject enemyPrefab, string enemyName) { Enemy newEnemy = Instantiate(enemyPrefab, enemyPos, Quaternion.identity).GetComponent <Enemy>(); newEnemy.SetTarget(Vector2.zero);//Move to the center newEnemy.enemyName = enemyName; newEnemy.GetComponentInChildren <TextMeshProUGUI>().color = activeColor; enemies.Add(newEnemy); }
public GameObject QueueEnemy(GameObject enemyPrefab, EnemySpawner enemySpawner) { GameObject enemyGameObject = Instantiate(enemyPrefab, GetLastEmptyPosition(), Quaternion.identity); Enemy enemy = enemyGameObject.GetComponent <Enemy>(); enemy.SetTarget(direction.transform); enemyList.Add(enemy); return(enemyGameObject); }
void SpawnEnemy(Transform position) { Vector3 direction = (endPoint.position - position.position).normalized; Transform enemyTransform = (Transform)Instantiate(enemyPrefab, position.position, Quaternion.LookRotation(direction)); GameObject enemyGO = enemyTransform.gameObject; Enemy enemy = enemyGO.GetComponent <Enemy>(); enemy.health += (0.005f * enemy.health); enemy.SetTarget(endPoint); }
public void Enter(Enemy e) { enemy = e; attackTimer = 0; isAttacking = true; enemy.StopMovement(); enemy.SetTarget(Enemy.TargetType.Player); enemy.ChangeAnimation(Enemy.AnimationState.Attack); }
void SpawnEnemy() { Transform spawnPosition = _spawnerPositions[Random.Range(0, _spawnerPositions.Length)]; GameObject enemy = Instantiate(_enemyPrefab, spawnPosition.position, Quaternion.identity); Enemy e = enemy.GetComponent <Enemy>(); if (e != null) { e.SetTarget(_enemyTarget); } }
private void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Player") { parent.SetTarget(col.transform); Debug.Log(col); } else { Debug.Log(col + "is the col"); } }
public void SpawnEnemyInProgress(string enemyType, Vector2 pos, int target) { PackedScene scene = enemyScenes[enemyType]; Enemy enemy = scene.Instance() as Enemy; enemy.SetPosition(pos); enemy.SetTarget(target); RemainingEnemies++; AddChild(enemy); }
private IEnumerator Spawn() { for (int i = 0; i < enemyQuantityPerRound; i++) { Transform _spawnPoint = spawnerPoints[Random.Range(0, spawnerPoints.Count)]; currentQuantity++; Enemy enemyCreated = Instantiate(enemyPrefab, _spawnPoint.position, Quaternion.identity); enemyCreated.Guy.onKill = () => currentQuantity--; int random = Random.Range(0, spawnPoints.Count - 1); enemyCreated.SetTarget(spawnPoints[random]); yield return(new WaitForSeconds(1)); } }
// Update is called once per frame void Update() { update += 500.0f * Time.deltaTime; if (update >= 500.0f) { update = 0.0f; if (target != null) { enemy.SetTarget(target); RaycastHit hit; //raycast towards them Vector3 dir = target.position - transform.parent.position; Vector3 aimUp = transform.parent.up * 0.8f; SquadMember testCrouch = target.GetComponent <SquadMember>(); if (testCrouch != null && testCrouch.GetCrouch()) { aimUp *= 0.0f; } Physics.Raycast(transform.parent.position + aimUp, dir, out hit); if (hit.collider != null && hit.collider.gameObject.tag != "SquadMan") { target = null; enemy.SetTarget(null); } } else { enemy.SetTarget(null); //gun.transform.localRotation = Quaternion.identity; } } }
public void SpawnEnemy() { int i = (int)(Random.value * (spawnPoints.Count - 1)); Enemy enemy = enemyPool.GetObject().GetComponent <Enemy>(); if (!enemy) { Debug.LogError("enemy not found"); } enemy.transform.position = spawnPoints[i].position; enemy.transform.rotation = spawnPoints[i].rotation; enemy.SetTarget(target); enemy.gameObject.SetActive(true); }