fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. // your code goes here
  8. }
  9. }
  10.  
Success #stdin #stdout 0.03s 21792KB
stdin
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class PenguinController : MonoBehaviour
{
    public float flapForce = 5f;
    public Text distanceText;
    public GameObject gameOverPanel;

    private Rigidbody2D rb;
    private Vector3 startPos;
    private bool isAlive = true;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        startPos = transform.position;
        gameOverPanel.SetActive(false);
    }

    void Update()
    {
        if (!isAlive) return;

        // 羽ばたき(長押し)
        if (Input.GetButton("Fire1"))
        {
            rb.velocity = new Vector2(rb.velocity.x, flapForce);
        }

        // 常に右方向に少し進む
        rb.velocity = new Vector2(2f, rb.velocity.y);

        // 距離計測
        float distance = transform.position.x - startPos.x;
        distanceText.text = "Distance: " + distance.ToString("F1") + "m";

        // 地面衝突でゲームオーバー
        if (transform.position.y < -4f)
        {
            GameOver();
        }
    }

    void GameOver()
    {
        isAlive = false;
        rb.velocity = Vector2.zero;
        gameOverPanel.SetActive(true);
    }

    public void Retry()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform target;
    public float smoothSpeed = 0.125f;
    public Vector3 offset;

    void LateUpdate()
    {
        if (target == null) return;

        Vector3 desiredPosition = new Vector3(
            target.position.x + offset.x,
            offset.y,
            offset.z
        );

        Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
        transform.position = smoothedPosition;
    }
}
stdout
Standard output is empty