-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemySpawner.cs
More file actions
30 lines (27 loc) · 842 Bytes
/
Copy pathEnemySpawner.cs
File metadata and controls
30 lines (27 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using UnityEngine;
public class EnemySpawner : MonoBehaviour
{
public GameObject skeletonPrefab; // Assign the skeleton prefab here
public Transform spawnPoint; // Optional: Set a spawn point in the scene
private void Update()
{
// Spawn a skeleton when the "S" key is pressed
if (Input.GetKeyDown(KeyCode.J))
{
SpawnSkeleton();
}
}
void SpawnSkeleton()
{
if (skeletonPrefab != null)
{
Vector3 spawnPosition = spawnPoint != null ? spawnPoint.position : transform.position;
Instantiate(skeletonPrefab, spawnPosition, Quaternion.identity);
Debug.Log("Skeleton spawned!");
}
else
{
Debug.LogError("Skeleton prefab is not assigned.");
}
}
}