using System.Collections; using System.Collections.Generic; using UnityEngine; public…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class BarrelSpawner : MonoBehaviour { public GameObject barrelPrefab; public Transform[] spawnPoints; // Points where barrels will be spawned public float spawnInterval = 3f; // Interval between barrel spawns
private bool isSpawning = true; private void Start() { InvokeRepeating("SpawnBarrel", 0f, spawnInterval); } private void SpawnBarrel() { int spawnIndex = Random.Range(0, spawnPoints.Length); Transform spawnPoint = spawnPoints[spawnIndex]; Instantiate(barrelPrefab, spawnPoint.position, Quaternion.identity); } public void StopSpawning() { isSpawning = false; CancelInvoke("SpawnBarrel"); }}
public class BarrelController : MonoBehaviour { public Transform[] movePoints; // Points where barrel moves public float moveSpeed = 3f; // Speed at which barrel moves private int currentPointIndex = 0;
private void Update() { MoveBarrel(); } private void MoveBarrel() { if (currentPointIndex >= movePoints.Length) { Destroy(gameObject); // Destroy barrel if it reaches the end return; } Transform targetPoint = movePoints[currentPointIndex]; transform.position = Vector3.MoveTowards(transform.position, targetPoint.position, moveSpeed * Time.deltaTime); if (transform.position == targetPoint.position) { currentPointIndex++; } }} modify this script allowing the barrels to go down a ladder game object (is on the ladder layer)
- Assistant
To modify the script to allow the barrels to go down a ladder game object, you can add some additional logic in the BarrelController script. Here's an updated version of the script: