43 lines
931 B
C#
43 lines
931 B
C#
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);
|
|
}
|
|
} |