LoginSignup
22
5

ひつじがいっぱい出るアプリ

Last updated at Posted at 2023-11-30

クソアプリ Advent Calendar 2023 1日目の記事です。

羊を数えれば寝れる。
せっかくなので羊が走る姿も見たい。
ということで作りました。

完成したもの

羊がいっぱい出ます。無限に数えられます。
数える以外の使い道がないのでクソアプリです。

中身

Unityで作りました。
結構シンプルです。

羊のイラストを手に入れて、いろいろやれば誰でも簡単に作れます。
↓羊が動く方

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HItujiMove : MonoBehaviour
{
    public int HitujiRandom;
    public GameObject Hituji;
    public string HitujiName;
    public Vector3 HitujiPos;
    // Start is called before the first frame update
    void Start()
    {
        Hituji.GetComponent<Transform>();
        HitujiRandom = Random.Range(-4, 4);
        HitujiPos.x = 5;
        HitujiPos.y=HitujiRandom;
        this.transform.position = HitujiPos;
        
    }

    // Update is called once per frame
    void Update()
    {
        HitujiName = this.name;
        if (HitujiName.Contains("Clone"))
        {
         
            this.transform.position = HitujiPos;
            HitujiPos.x -= 0.5f;
           
            if (HitujiPos.x <= -8)
            {
                Destroy(gameObject);

            }
        }
    }
}

↓羊が生まれる方

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;

public class HitujiUmareru: MonoBehaviour
{
   
    public GameObject Hituji;
  
  
   
    
    public int time;
    // Start is called before the first frame update
    void Start()
    {
        time = 0;
     
    }

    // Update is called once per frame
    void Update()
    {
        time = time + 1;
      
        if (time >= Random.Range(6,20))
        {
            var HitujiClone =Instantiate(Hituji);
            HitujiClone.GetComponent<HItujiMove>();
            time = 0;
        }
    }
}

羊のクローンを作成して、名前にクローンが入っている羊だけ動かしています。
ランダムで羊がでて、特定の位置まで来たら勝手に消えます。
それだけです。

使った感想

目が覚めた

22
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
5