Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ProjectileSpawner : MonoBehaviour
- {
- // Projectile to Spawn
- public GameObject projectile;
- // Where to Spawn the Projectiles
- public Transform spawnLocation;
- // Rotation of Projectile on Spawn
- public Quaternion spawnRotation;
- public DetectionZone detectionZone;
- public AudioSource spawnAudioSource;
- public float spawnTime = 0.5f;
- private float timeSinceSpawned = 0.5f;
- // Update is called once per frame
- private void Update()
- {
- if (detectionZone.detectedObjs.Count > 0)
- {
- timeSinceSpawned += Time.deltaTime;
- if (timeSinceSpawned >= spawnTime)
- {
- Instantiate(projectile, spawnLocation.position, spawnRotation);
- if (spawnAudioSource.clip)
- {
- spawnAudioSource.Play();
- }
- timeSinceSpawned = 0;
- }
- }
- else
- {
- timeSinceSpawned = 0.5f;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement