Add JumpPad feature with prefab and adapter implementation
This commit is contained in:
25
Assets/Scripts/Infrastructure/Unity/JumpPadAdapter.cs
Normal file
25
Assets/Scripts/Infrastructure/Unity/JumpPadAdapter.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Infrastructure.Unity
|
||||
{
|
||||
public class JumpPadAdapter : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float jumpForce = 15f;
|
||||
[SerializeField] private ParticleSystem jumpVfx;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent<PlayerController>(out var player))
|
||||
{
|
||||
var vel = player.Rigidbody.linearVelocity;
|
||||
vel.y = 0f;
|
||||
player.Rigidbody.linearVelocity = vel;
|
||||
|
||||
player.Rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
|
||||
if (jumpVfx) jumpVfx.Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5de94b384aac49a7baa41967735126b0
|
||||
timeCreated: 1765574197
|
||||
@@ -9,6 +9,7 @@ namespace Infrastructure.Unity
|
||||
[Header("Prefabs")]
|
||||
[SerializeField] private TileViewAdapter tilePrefab;
|
||||
[SerializeField] private ParticleSystem tileBreakVfxPrefab;
|
||||
[SerializeField] private JumpPadAdapter jumpPadPrefab;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private int gridSizeX = 10;
|
||||
@@ -44,6 +45,14 @@ namespace Infrastructure.Unity
|
||||
var pos = new Vector3(coord.x - xOffset, yOffset, coord.y - zOffset);
|
||||
CreateTile(pos, $"{floorIndex}_{coord.x}_{coord.y}", floorIndex, soundManager, allTiles, tileViews);
|
||||
}
|
||||
|
||||
if (floorIndex > 0 && jumpPadPrefab)
|
||||
{
|
||||
var validSpot = coordinates[Random.Range(0, coordinates.Count)];
|
||||
var padPos = new Vector3(validSpot.x - xOffset, yOffset + 0.6f, validSpot.y - zOffset);
|
||||
|
||||
Instantiate(jumpPadPrefab, padPos, Quaternion.identity, transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateTile(Vector3 position, string id, int floorIndex, SoundManager soundManager,
|
||||
|
||||
Reference in New Issue
Block a user