VerticalBird minihra v procesu
This commit is contained in:
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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user