nejlepsi minihra, velmi dobre funguje, nepouzil jsem chatbota nai jednoud a vsechno jsem programoval pomoci libraries a moc me to bavilo, esing neni nejaky skvely ale funguje to na iphone, takze se to mozna rozbije pokud to zkusite runnout na androidu
This commit is contained in:
27
Assets/Scripts/FollowPositionOnly.cs
Normal file
27
Assets/Scripts/FollowPositionOnly.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FollowParentPositionOnly : MonoBehaviour
|
||||
{
|
||||
public Transform parent;
|
||||
private Quaternion initialRotation;
|
||||
private Vector3 worldOffset;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (parent == null)
|
||||
parent = transform.parent;
|
||||
|
||||
// Store offset in WORLD space
|
||||
worldOffset = transform.position - parent.position;
|
||||
initialRotation = transform.rotation;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (parent == null) return;
|
||||
|
||||
// Move child using stored world offset
|
||||
transform.position = parent.position + worldOffset;
|
||||
transform.rotation = initialRotation;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/FollowPositionOnly.cs.meta
Normal file
2
Assets/Scripts/FollowPositionOnly.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b159266533f64ba4eb30ef6112cc4611
|
||||
30
Assets/Scripts/GyroPlatformController.cs
Normal file
30
Assets/Scripts/GyroPlatformController.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GyroPlatformController : MonoBehaviour
|
||||
{
|
||||
public Rigidbody ball;
|
||||
public float forceStrength = 30f;
|
||||
public float dampingPerSecond = 0.9f;
|
||||
void Start()
|
||||
{
|
||||
if (SystemInfo.supportsGyroscope)
|
||||
{
|
||||
Input.gyro.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (ball == null) return;
|
||||
|
||||
Vector3 g = Input.gyro.gravity;
|
||||
|
||||
Vector3 force = new Vector3(g.x, 0f, g.y);
|
||||
|
||||
ball.AddForce(force * forceStrength, ForceMode.Acceleration);
|
||||
|
||||
float frameDamping = Mathf.Pow(dampingPerSecond, Time.deltaTime);
|
||||
|
||||
ball.linearVelocity *= frameDamping;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/GyroPlatformController.cs.meta
Normal file
2
Assets/Scripts/GyroPlatformController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d665da208a5a3ad408e85341263c60e5
|
||||
33
Assets/Scripts/HoleGoalTrigger.cs
Normal file
33
Assets/Scripts/HoleGoalTrigger.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class HoleGoalTrigger : MonoBehaviour
|
||||
{
|
||||
[Tooltip("Optional: assign the ball rigidbody or leave empty to accept any Rigidbody with tag Ball.")]
|
||||
public Rigidbody ballRigidbody;
|
||||
|
||||
[Tooltip("If true, checks tag 'Ball' when ballRigidbody not assigned.")]
|
||||
public bool requireBallTag = true;
|
||||
|
||||
public System.Action OnBallScored;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (ballRigidbody != null)
|
||||
{
|
||||
if (other.attachedRigidbody == ballRigidbody)
|
||||
{
|
||||
OnBallScored?.Invoke();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (other.attachedRigidbody == null) return;
|
||||
|
||||
if (requireBallTag)
|
||||
{
|
||||
if (!other.CompareTag("Ball")) return;
|
||||
}
|
||||
|
||||
OnBallScored?.Invoke();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/HoleGoalTrigger.cs.meta
Normal file
2
Assets/Scripts/HoleGoalTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6bad0eb7441229448191433d8a9f758
|
||||
30
Assets/Scripts/PlayAudioOnCamera.cs
Normal file
30
Assets/Scripts/PlayAudioOnCamera.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayAudioOnCamera : MonoBehaviour
|
||||
{
|
||||
public AudioClip clip; // assign your audio file in the Inspector
|
||||
private AudioSource audioSource;
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Get or add an AudioSource to this GameObject
|
||||
audioSource = gameObject.GetComponent<AudioSource>();
|
||||
if (audioSource == null)
|
||||
{
|
||||
audioSource = gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
|
||||
// Assign the audio clip
|
||||
if (clip != null)
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.playOnAwake = false;
|
||||
audioSource.loop = false; // change to true if you want looping
|
||||
audioSource.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("PlayAudioOnCamera: No audio clip assigned!");
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayAudioOnCamera.cs.meta
Normal file
2
Assets/Scripts/PlayAudioOnCamera.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37f33c8b63e5b384db6a385b909b27aa
|
||||
29
Assets/Scripts/TeleportOnTrigger.cs
Normal file
29
Assets/Scripts/TeleportOnTrigger.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TeleportOnTrigger : MonoBehaviour
|
||||
{
|
||||
[Header("Teleport Target")]
|
||||
public Transform targetPosition;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (targetPosition == null) return;
|
||||
|
||||
Rigidbody rb = other.attachedRigidbody;
|
||||
|
||||
if (rb != null)
|
||||
{
|
||||
// STOP ALL MOTION
|
||||
rb.linearVelocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
|
||||
// TELEPORT
|
||||
rb.position = targetPosition.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-physics objects
|
||||
other.transform.position = targetPosition.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/TeleportOnTrigger.cs.meta
Normal file
2
Assets/Scripts/TeleportOnTrigger.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e101cb487f02244592e16548d98f0b5
|
||||
187
Assets/Scripts/TiltHoleMiniGameManager.cs
Normal file
187
Assets/Scripts/TiltHoleMiniGameManager.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class TiltHoleMiniGameManager : MonoBehaviour, ITask
|
||||
{
|
||||
// =========================
|
||||
// ITask PROPERTIES
|
||||
// =========================
|
||||
|
||||
public string TaskID { get; private set; } = "TILT_HOLE_01";
|
||||
public TaskType TaskType { get; private set; } = TaskType.Task;
|
||||
public string TaskName { get; private set; } = "Tilt Ball Into Hole";
|
||||
public (double, double) TaskLocation { get; private set; } = (0, 0);
|
||||
public bool IsCompleted { get; private set; }
|
||||
|
||||
private Action<ITask> _onCompletedCallback;
|
||||
|
||||
// =========================
|
||||
// MINIGAME REFERENCES
|
||||
// =========================
|
||||
|
||||
[Header("References")]
|
||||
public GyroPlatformController platformController;
|
||||
public HoleGoalTrigger goalTrigger;
|
||||
public Rigidbody ball;
|
||||
|
||||
[Header("Audio")]
|
||||
public AudioClip startSound;
|
||||
public AudioClip winSound;
|
||||
|
||||
private AudioSource audioSource;
|
||||
|
||||
[Header("Game State")]
|
||||
public bool isActive = false;
|
||||
|
||||
[Header("Win Behavior")]
|
||||
public bool freezeOnWin = true;
|
||||
public bool disableBallOnWin = false;
|
||||
|
||||
// =========================
|
||||
// UNITY LIFECYCLE
|
||||
// =========================
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (platformController == null) platformController = FindFirstObjectByType<GyroPlatformController>();
|
||||
if (goalTrigger == null) goalTrigger = FindFirstObjectByType<HoleGoalTrigger>();
|
||||
|
||||
if (Camera.main != null)
|
||||
{
|
||||
audioSource = Camera.main.GetComponent<AudioSource>();
|
||||
if (audioSource == null)
|
||||
audioSource = Camera.main.gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (goalTrigger != null)
|
||||
{
|
||||
goalTrigger.OnBallScored += HandleWin;
|
||||
}
|
||||
|
||||
if (ball != null && goalTrigger != null)
|
||||
{
|
||||
goalTrigger.ballRigidbody = ball;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (goalTrigger != null)
|
||||
goalTrigger.OnBallScored -= HandleWin;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// TASK LIFECYCLE
|
||||
// =========================
|
||||
|
||||
public void Initialize(Action<ITask> onCompleted)
|
||||
{
|
||||
Debug.Log("Initializing Tilt Hole Task");
|
||||
|
||||
IsCompleted = false;
|
||||
isActive = true;
|
||||
_onCompletedCallback = onCompleted;
|
||||
|
||||
if (platformController != null)
|
||||
platformController.enabled = true;
|
||||
|
||||
if (ball != null)
|
||||
{
|
||||
ball.isKinematic = false;
|
||||
ball.linearVelocity = Vector3.zero;
|
||||
ball.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
if (startSound != null && audioSource != null)
|
||||
{
|
||||
audioSource.PlayOneShot(startSound);
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitTask(Action<ITask> onExit)
|
||||
{
|
||||
Debug.Log("Exiting Tilt Hole Task");
|
||||
|
||||
isActive = false;
|
||||
|
||||
if (platformController != null)
|
||||
platformController.enabled = false;
|
||||
|
||||
onExit?.Invoke(this);
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
if (IsCompleted) return;
|
||||
|
||||
Debug.Log("Task Complete: Tilt Hole");
|
||||
|
||||
IsCompleted = true;
|
||||
isActive = false;
|
||||
|
||||
if (winSound != null && audioSource != null)
|
||||
{
|
||||
audioSource.PlayOneShot(winSound);
|
||||
}
|
||||
|
||||
_onCompletedCallback?.Invoke(this);
|
||||
ExitTask(null);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// MINIGAME WIN EVENT
|
||||
// =========================
|
||||
|
||||
private void HandleWin()
|
||||
{
|
||||
if (!isActive) return;
|
||||
|
||||
Debug.Log("Ball reached hole.");
|
||||
|
||||
if (freezeOnWin)
|
||||
{
|
||||
if (platformController != null)
|
||||
platformController.enabled = false;
|
||||
|
||||
if (ball != null)
|
||||
{
|
||||
ball.linearVelocity = Vector3.zero;
|
||||
ball.angularVelocity = Vector3.zero;
|
||||
ball.isKinematic = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (disableBallOnWin && ball != null)
|
||||
{
|
||||
ball.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
Complete(); // 🔥 THIS completes the task
|
||||
}
|
||||
|
||||
// =========================
|
||||
// DEBUG GUI
|
||||
// =========================
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
GUIStyle s = new GUIStyle(GUI.skin.label);
|
||||
s.fontSize = 24;
|
||||
|
||||
if (isActive)
|
||||
{
|
||||
s.normal.textColor = Color.white;
|
||||
GUI.Label(new Rect(10, 10, 700, 30),
|
||||
"Goal: Tilt platform to roll the ball into the hole.", s);
|
||||
}
|
||||
else if (IsCompleted)
|
||||
{
|
||||
s.normal.textColor = Color.yellow;
|
||||
GUI.Label(new Rect(10, 10, 700, 30),
|
||||
"Task Completed!", s);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/TiltHoleMiniGameManager.cs.meta
Normal file
2
Assets/Scripts/TiltHoleMiniGameManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f70c5a8e211b7142b26b4ea95bf2348
|
||||
2
Assets/Scripts/WindController.cs.meta
Normal file
2
Assets/Scripts/WindController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2d62d3ffa507924ab3a6fd97f185f3e
|
||||
Reference in New Issue
Block a user