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); // Spawn initial barrels SpawnInitialBarrels(); } private void SpawnInitialBarrels() { // Create an array of positions Vector3[] initialPositions = new Vector3[] { new Vector3(-6f, -3.25f, 0f), new Vector3(6f, -1.25f, 0f), new Vector3(-6f, 0.75f, 0f), new Vector3(6f, 2.75f, 0f) }; // Loop through each position and spawn a barrel foreach (Vector3 position in initialPositions) { Instantiate(barrelPrefab, position, Quaternion.identity); } } 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 Transform ladderPoint; // Point where barrel goes down the ladder 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; } if (movePoints[currentPointIndex] == ladderPoint) { // Handle ladder movement separately MoveBarrelDownLadder(); } else { // Move barrel to target point Transform targetPoint = movePoints[currentPointIndex]; transform.position = Vector3.MoveTowards(transform.position, targetPoint.position, moveSpeed * Time.deltaTime); if (transform.position == targetPoint.position) { currentPointIndex++; } } } private void MoveBarrelDownLadder() { // Move barrel down the ladder Vector3 ladderExitPoint = ladderPoint.position + new Vector3(0, -1, 0); // Point where barrel exits the ladder transform.position = Vector3.MoveTowards(transform.position, ladderExitPoint, moveSpeed * Time.deltaTime); if (transform.position == ladderExitPoint) { currentPointIndex++; } }} make it so when a barrel collides with a BarrelChute game object (set to BarrelChute layer) it only moves down on the Y axis (velocity of 0) and can phase through 1 platform (set to the platform layer) and will reset when it hit the second platform
- Assistant