123
anonymous No title
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public class SetTileShadow : MonoBehaviour
{
    [SerializeField] Tilemap tile;
    [SerializeField] int length = 8;

    private void OnValidate()
    {
        if (!tile) tile = GetComponent<Tilemap>();
    }

    private void Start()
    {
        Set();
    }

    public void Set()
    {
        tile.CompressBounds();
        var bound = tile.cellBounds;

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
        sw.Start();
        //最初に全タイルを黒くする
        for (int x = bound.min.x; x < bound.max.x; x++)
        {
            for (int y = bound.min.y; y < bound.max.y; y++)
            {
                Color b = Color.black;
                if (tile.HasTile(new Vector3Int(x, y, 0))) tile.SetColor(new Vector3Int(x, y, 0), b);
            }
        }

        //上から下に白を広げる
        for (int x = bound.min.x; x < bound.max.x; x++)
        {
            for (int y = bound.min.y + 5; y < bound.max.y; y++)
            {
                if (!tile.HasTile(new Vector3Int(x, y + 1, 0)) && tile.HasTile(new Vector3Int(x, y, 0)))
                {
                    for (int f = 0; f <= length; f++)
                    {
                        float tc = tile.GetColor(new Vector3Int(x, y - f, 0)).r;
                        float c = ((float)length - f) / (float)length;
                        float b = Mathf.Max(tc, c);
                        tile.SetColor(new Vector3Int(x, y - f), new Color(b, b, b, 1));

                        //更に左に影響を与える
                        for (int fx = 0; fx < length - f; fx++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x - fx, y - f, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fx) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x - fx, y - f), new Color(fb, fb, fb, 1));
                        }

                        //更に右に影響を与える
                        for (int fx = 0; fx < length - f; fx++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x + fx, y - f, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fx) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x + fx, y - f), new Color(fb, fb, fb, 1));
                        }
                    }
                }
            }
        }

        //左から右にに白を広げる
        for (int x = bound.max.x - 5; x > bound.min.x; x--)
        {
            for (int y = bound.min.y; y < bound.max.y; y++)
            {
                if (!tile.HasTile(new Vector3Int(x - 1, y, 0)) && tile.HasTile(new Vector3Int(x, y, 0)))
                {
                    for (int f = 0; f <= length; f++)
                    {
                        float tc = tile.GetColor(new Vector3Int(x + f, y, 0)).r;
                        float c = ((float)length - f) / (float)length;
                        float b = Mathf.Max(tc, c);
                        tile.SetColor(new Vector3Int(x + f, y), new Color(b, b, b, 1));

                        //更に下に影響を与える
                        for (int fy = 0; fy < length - f; fy++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x + f, y - fy, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fy) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x + f, y - fy), new Color(fb, fb, fb, 1));
                        }

                        //更に上に影響を与える
                        for (int fy = 0; fy < length - f; fy++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x + f, y + fy, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fy) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x + f, y + fy), new Color(fb, fb, fb, 1));
                        }
                    }
                }
            }
        }

        //下から上に白を広げる
        for (int x = bound.min.x; x < bound.max.x; x++)
        {
            for (int y = bound.max.y - 5; y > bound.min.y; y--)
            {
                if (!tile.HasTile(new Vector3Int(x, y - 1, 0)) && tile.HasTile(new Vector3Int(x, y, 0)))
                {
                    for (int f = 0; f <= length; f++)
                    {
                        float tc = tile.GetColor(new Vector3Int(x, y + f, 0)).r;
                        float c = ((float)length - f) / (float)length;
                        float b = Mathf.Max(tc, c);
                        tile.SetColor(new Vector3Int(x, y + f), new Color(b, b, b, 1));

                        //更に左に影響を与える
                        for (int fx = 0; fx < length - f; fx++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x - fx, y + f, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fx) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x - fx, y + f), new Color(fb, fb, fb, 1));
                        }

                        //更に右に影響を与える
                        for (int fx = 0; fx < length - f; fx++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x + fx, y + f, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fx) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x + fx, y + f), new Color(fb, fb, fb, 1));
                        }
                    }
                }
            }
        }

        //右から左にに白を広げる
        for (int x = bound.min.x + 5; x < bound.max.x; x++)
        {
            for (int y = bound.min.y; y < bound.max.y; y++)
            {
                if (!tile.HasTile(new Vector3Int(x + 1, y, 0)) && tile.HasTile(new Vector3Int(x, y, 0)))
                {
                    for (int f = 0; f <= length; f++)
                    {
                        float tc = tile.GetColor(new Vector3Int(x - f, y, 0)).r;
                        float c = ((float)length - f) / (float)length;
                        float b = Mathf.Max(tc, c);
                        tile.SetColor(new Vector3Int(x - f, y), new Color(b, b, b, 1));

                        //更に下に影響を与える
                        for (int fy = 0; fy < length - f; fy++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x - f, y - fy, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fy) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x - f, y - fy), new Color(fb, fb, fb, 1));
                        }

                        //更に上に影響を与える
                        for (int fy = 0; fy < length - f; fy++)
                        {
                            float ftc = tile.GetColor(new Vector3Int(x - f, y + fy, 0)).r;
                            float fc = Mathf.Lerp(0, b, (((float)length - f) - fy) / (float)length);
                            float fb = Mathf.Max(ftc, fc);
                            tile.SetColor(new Vector3Int(x - f, y + fy), new Color(fb, fb, fb, 1));
                        }
                    }
                }
            }
        }

        sw.Stop();
        Debug.Log($"陰をつける処理にかかった時間 : {sw.ElapsedMilliseconds} ms");
    }
}
anonymous ゴールにあたったらゲームクリア
C#
anonymous No title
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsApp3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox1.Text = "<html>\n";
            richTextBox1.AppendText("<head>\n");
            richTextBox1.AppendText("<meta http-equiv=" + "refresh" + "");
        }
    }
}
anonymous No title
C#
long x = 0;
while (true) {
x++;
}
anonymous No title
C#
 //プレイヤーが跳ねる雲
    void OnCollisionStay2D(Collision2D other)
    {
         elapsedTime += Time.deltaTime;

         if (Input.GetKeyDown(KeyCode.Space))
         {
            jump = true;
         }

        if (other.collider.gameObject.tag == "Tranp")
        {

            if (elapsedTime >= untilJump)
            {
                if (jump)
                {
                    this.rigid2D.AddForce(transform.up * this.jumpForce * 1.2f);
                    elapsedTime = 0;
                    jump = false;
                }
                else
                {
                    this.rigid2D.AddForce(transform.up * this.jumpForce * 0.3f);
                }

            }

        }
    }

        void OnCollisionExit2D(Collision2D other)
        {
            elapsedTime = 0;
            jump = false;
        }
anonymous No title
C#
public class PlayerController : MonoBehaviour
{
    Rigidbody2D rigid2D;
    Animator animator;
    float jumpForce = 680.0f;
    float walkForce = 30.0f;
    float maxWalkSpeed = 2.0f;
    GameObject player;


    // Start is called before the first frame update
    void Start()
    {
        this.rigid2D = GetComponent<Rigidbody2D>();
        this.animator = GetComponent<Animator>();
        this.player = GameObject.Find("cat");
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            this.rigid2D.AddForce(transform.up * this.jumpForce);
        }

        int key = 0;
        if (Input.GetKey(KeyCode.RightArrow)) key = 1;
        if (Input.GetKey(KeyCode.LeftArrow)) key = -1;

        float speedx = Mathf.Abs(this.rigid2D.velocity.x);

        if (speedx < maxWalkSpeed)
        {
            this.rigid2D.AddForce(transform.right * key * this.walkForce);
        }

        if (key != 0)
        {
            transform.localScale = new Vector3(key, 1, 1);

        }
        this.animator.speed = speedx / 2.0f;


        //プレイヤーの位置を取得
        Transform playerPos = this.player.transform;
        //座標を取得
        Vector3 pos = playerPos.position;

        if (pos.x < -3f)
        {
            pos.x = 3f;
            playerPos.position = pos;
        }
        else if (pos.x > 3f)
        {
            pos.x = -3f;
            playerPos.position = pos;
        }

    }

    void OnTriggerEnter2D(Collider2D other)
    {
        UnityEngine.Debug.Log("ゴール");
        SceneManager.LoadScene("ClearScene");
    }

}
anonymous No title
C#
public class PlayerController : MonoBehaviour
{
    public Rigidbody2D rb;

    // Start is called before the first frame update
    void Start()
    {
        rb = this.GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        //左矢印が押された時
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            rb.velocity = new Vector3(-3f, 0, 0);
        }
        else if(Input.GetKeyUp(KeyCode.LeftArrow))
        {
            rb.velocity = new Vector3(0, 0, 0);
        }

        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            rb.velocity = new Vector3(3f, 0, 0);
        }
        else if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            rb.velocity = new Vector3(0, 0, 0);
        }
    }
}
anonymous No title
C#
public class CarController : MonoBehaviour
{
    float speed = 0;
    Vector2 startPos;
    float starttime = 0f;
    float endtime = 0f;

    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        //スワイプの長さを決める(追加)
        if (Input.GetMouseButtonDown(0))
        {
            //マウスをクリックした座標
            this.startPos = Input.mousePosition;

            //マウスをクリックした時間
            starttime = Time.time;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            //マウスを離した座標
            Vector2 endPos = Input.mousePosition;
            float swipeLength = endPos.x - this.startPos.x;

            //マウスを離した時間
            endtime = Time.time;

            //経過時間
            float timespan = (endtime - starttime) * 1000;

            //スワイプの長さを初速度に変換する
            speed = swipeLength / timespan;
        }

        transform.Translate(speed, 0, 0); //移動
        speed *= 0.98f; //速度
    }
}
anonymous No title
C#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarController : MonoBehaviour
{
    float speed = 0;
    Vector2 startPos;
    float strTime;
    float endTime;
    float spTime;

    // Start is called before the first frame update
    void Start()
    {
    

    }

    // Update is called once per frame
    void Update()
    {
        //スワイプの長さを決める(追加)
        if (Input.GetMouseButtonDown(0))
        {
            //マウスをクリックした座標
            this.startPos = Input.mousePosition;

            // マウスをクリックした時間
            strTime = Time.deltaTime;            

        }else if (Input.GetMouseButtonUp(0))
        {
            //マウスを離した座標
            Vector2 endPos = Input.mousePosition;
            float swipeLength = endPos.x - this.startPos.x;

            //マウスを離した時間
            endTime = Time.deltaTime;
            spTime = endTime - strTime;

            //スワイプの長さを初速度に変換する
            speed = swipeLength / spTime;
        }

        transform.Translate(speed, 0, 0); //移動
        speed *= 0.98f; //速度
    }
}
anonymous No title
C#
    public static void Main(){

            const float beginX = 800;//開始X座標
            const float endX = 340;//終了X座標
            const float rate = 0.05f;//移動量の係数(0fに近いほど遅く1fに近づくほど速い)
            float x = 0f;
            pictureBox1.Left = (int) beginX;
            while (Math.Abs(beginX - x - endX) >= 1) {
            	pictureBox1.Left = (int) (beginX - x);
            	x += (beginX - endX) * rate;
            	pictureBox1.Refresh();
            	wait();
            }
            pictureBox1.Left = (int) endX;
        }
        
        private static async void wait() {
            await Task.Delay(16);//60FPS(16ms)で再描画
        } 
Don't you submit code?
Submit
123