VerticalBird minihra v procesu
This commit is contained in:
43
Assets/Scripts/VerticalBird/PohybPrekazkay.cs
Normal file
43
Assets/Scripts/VerticalBird/PohybPrekazkay.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class Obstacle : MonoBehaviour
|
||||
{
|
||||
public float fallSpeed = 200f;
|
||||
public RectTransform robot;
|
||||
public float hitDistance = 60f;
|
||||
public string nextScene = "GameOver";
|
||||
|
||||
private RectTransform rectTransform;
|
||||
private bool isHit = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isHit) return;
|
||||
|
||||
// Pád dolù
|
||||
rectTransform.anchoredPosition += Vector2.down * fallSpeed * Time.deltaTime;
|
||||
|
||||
// Detekce dotyku
|
||||
float distance = Vector2.Distance(
|
||||
rectTransform.anchoredPosition,
|
||||
robot.anchoredPosition
|
||||
);
|
||||
|
||||
if (distance < hitDistance)
|
||||
{
|
||||
isHit = true;
|
||||
Invoke("LoadNextScene", 0.5f);
|
||||
}
|
||||
}
|
||||
|
||||
void LoadNextScene()
|
||||
{
|
||||
SceneManager.LoadScene(nextScene);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user