/// <summary> /// This function spawns an enemy at a given spawn point when called. /// </summary> public void SpawnEnemy() { GameObject enemy = Instantiate(enemyPrefab, spawnPoint.position, Quaternion.identity); NPCEnemy npc = enemy.GetComponent <NPCEnemy>(); npc.playerTransform = player.transform; }
/// <summary> /// This code determines if the ray gun hits an enemy or a rock and applies the appropriate amount of damage depending on which object is hit. /// The laser pistol is for shooting aliens only, no destroying objects. /// </summary> public void RaycastFire() { audioSource.PlayOneShot(impact, 0.3F); RaycastHit hit; if (Physics.Raycast(firePosition.transform.position, firePosition.transform.forward, out hit)) { Debug.Log(hit.transform.name); // This is commented because I decided that the laser pistol should only be able to hit/damage enemy aliens and not rocks. //ObjectRecieveDamage rock = hit.transform.GetComponent<ObjectRecieveDamage>(); //if (rock != null) //{ // rock.TakeDamage(.3f); //} // If we hit an enemy we call the enemies ApplyDamage() function. NPCEnemy enemy = hit.transform.GetComponent <NPCEnemy>(); if (enemy != null) { enemy.ApplyDamage(damage); } GameObject bulletObject = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation); GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 1f); Destroy(bulletObject, 1f); } }
/// <summary> /// This code determines if the ray gun hits an enemy or a rock and applies the appropriate amount of damage depending on which object is hit. /// </summary> public void RaycastFire() { RaycastHit hit; if (Physics.Raycast(firePosition.transform.position, firePosition.transform.forward, out hit, range)) { Debug.Log(hit.transform.name); ObjectRecieveDamage rock = hit.transform.GetComponent <ObjectRecieveDamage>(); if (rock != null) { rock.TakeDamage(.3f); } NPCEnemy enemy = hit.transform.GetComponent <NPCEnemy>(); if (enemy != null) { enemy.ApplyDamage(1f); } GameObject impactGO = Instantiate(impactEffect, hit.point, Quaternion.LookRotation(hit.normal)); Destroy(impactGO, 1f); } }
// This function is checking if all the enemies in the wave have been eliminated and if they have it starts a timer until the beginning of the next wave. public void EnemyEliminated(NPCEnemy enemy) { enemiesEliminated++; if (enemiesToEliminate - enemiesEliminated <= 0) { //Start next wave newWaveTimer = 10; waitingForWave = true; waveNumber++; } }
// Update is called once per frame void Update() { if (waitingForWave) { if (newWaveTimer >= 0) { newWaveTimer -= Time.deltaTime; } else { //Initialize new wave enemiesToEliminate = waveNumber * enemiesPerWave; enemiesEliminated = 0; totalEnemiesSpawned = 0; waitingForWave = false; } } else { if (Time.time > nextSpawnTime) { nextSpawnTime = Time.time + spawnInterval; //Spawn enemy if total enemies is less than enemies needed to eliminate if (totalEnemiesSpawned < enemiesToEliminate) { Transform randomPoint = spawnPoints[Random.Range(0, spawnPoints.Length - 1)]; //Spawns an enemy at a random spawnpoint GameObject enemy = Instantiate(enemyPrefab, randomPoint.position, Quaternion.identity); NPCEnemy npc = enemy.GetComponent <NPCEnemy>(); npc.playerTransform = player.transform; npc.es = this; totalEnemiesSpawned++; } } } if (player.playerHP <= 0) { if (Input.GetKeyDown(KeyCode.Space)) { Scene scene = SceneManager.GetActiveScene(); SceneManager.LoadScene(scene.name); } } }
// Start is called before the first frame update void Start() { Transform randomPoint = spawnPoints[Random.Range(0, spawnPoints.Length - 1)]; GameObject enemy = Instantiate(enemyPrefab, randomPoint.position, Quaternion.identity); NPCEnemy npc = enemy.GetComponent <NPCEnemy>(); npc.playerTransform = player.transform; npc.aggroDistance = aggroDistance; npc.es = this; totalEnemiesSpawned++; //Lock cursor //Cursor.lockState = CursorLockMode.Locked; //Cursor.visible = false; //Wait 10 seconds for new wave to start //newWaveTimer = TimeToNextWave; //waitingForWave = true; }
public ActorObj CreateAvatar(int avatarType) { ActorObj actor = null; AvatarType type = (AvatarType)avatarType; switch (type) { case AvatarType.NPC_Player: actor = new NPCPlayer(); break; case AvatarType.NPC_Enemy: actor = new NPCEnemy(); break; default: break; } return(actor); }
private void SetButtonString(Button b, NPCEnemy npc) { string generalName = DBConfigMgr.Instance.MapGeneral[npc.GeneralConfigID].Name; string generalLv = npc.GeneralLevel.ToString(); b.Text = string.Format("{{0}}-{1}级", generalName, generalLv); }