0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity C# 自作Randamクラス

Posted at

##0.0 はじめに
using Systemを追加したらRandamクラスはUnityEngineの明示が必要となります。
ほかにも方法がありますが、対策しないとエラーになります。
Systemとぶつからない様にするためのいろいろと検討しましたが、自作Randamクラス(Randクラス)を使うのが簡単でした。

##1.0 スクリプト
以下はint, floatでランダムな数字を入手するための関数を入れています。

Rand.cs
using UnityEngine;

// using Systemを使ったときにぶつからない様にするための疑似Randamクラス
public static class Rand{

    /// <summary>
    /// minとmaxの間のランダムなintを返す。min含む、max含まない。
    /// </summary>
    public static int Range(int min, int max) {
        return Random.Range(min, max);
    }

    /// <summary>
    /// minとmaxの間のランダムなfloatを返す。min含む、max含む。
    /// </summary>
    public static float Range(float min, float max) {
        return Random.Range(min, max);
    }

}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?