VerticalBird minihra v procesu
This commit is contained in:
8
Assets/Scripts/VerticalBird.meta
Normal file
8
Assets/Scripts/VerticalBird.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60deea8957442ea4f9bee12bb4c30e9e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/VerticalBird/PohybPrekazkay.cs.meta
Normal file
2
Assets/Scripts/VerticalBird/PohybPrekazkay.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eab4e2853fd152d4cabdb9fee0470bf2
|
||||
62
Assets/Scripts/VerticalBird/PohybRobota.cs
Normal file
62
Assets/Scripts/VerticalBird/PohybRobota.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RobotMovement : MonoBehaviour
|
||||
{
|
||||
public float moveDistance = 100f; // pixely, ne metry!
|
||||
public float moveSpeed = 500f;
|
||||
|
||||
private RectTransform rectTransform;
|
||||
private Vector2 targetPosition;
|
||||
private bool isMoving = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
targetPosition = rectTransform.anchoredPosition;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (rectTransform.anchoredPosition.x > 450f)
|
||||
{
|
||||
rectTransform.anchoredPosition = new Vector2(450f, rectTransform.anchoredPosition.y);
|
||||
Debug.Log("maximální pozice");
|
||||
}
|
||||
|
||||
if (rectTransform.anchoredPosition.x < -450f)
|
||||
{
|
||||
rectTransform.anchoredPosition = new Vector2(-450f, rectTransform.anchoredPosition.y);
|
||||
Debug.Log("maximální pozice");
|
||||
}
|
||||
|
||||
if (isMoving)
|
||||
{
|
||||
rectTransform.anchoredPosition = Vector2.MoveTowards(
|
||||
rectTransform.anchoredPosition,
|
||||
targetPosition,
|
||||
moveSpeed * Time.deltaTime
|
||||
);
|
||||
|
||||
if (Vector2.Distance(rectTransform.anchoredPosition, targetPosition) < 0.5f)
|
||||
{
|
||||
rectTransform.anchoredPosition = targetPosition;
|
||||
isMoving = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveRight()
|
||||
{
|
||||
targetPosition = rectTransform.anchoredPosition + Vector2.right * moveDistance;
|
||||
isMoving = true;
|
||||
Debug.Log("pohyb do P");
|
||||
}
|
||||
|
||||
public void MoveLeft()
|
||||
{
|
||||
targetPosition = rectTransform.anchoredPosition + Vector2.left * moveDistance;
|
||||
isMoving = true;
|
||||
Debug.Log("pohyb do L");
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/VerticalBird/PohybRobota.cs.meta
Normal file
2
Assets/Scripts/VerticalBird/PohybRobota.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96391466c7655e8478d0400128f3640b
|
||||
Reference in New Issue
Block a user