コミュ障だから明日が僕らをよんだって返事もろくにしなかった

何かを創る人に憧れたからブログをはじめたんだと思うよ

びぎなーいずふぉーえばー

おわらせた

はい、おはようございます。そんなわけでポエム投稿兼Unityチュートリアル進捗報告用に使っていた連続エントリーをみなさまの熱い声援(?)のおかげでおわらせることができました。

以前の記事
inujini.hatenablog.com


それではお作法の確認を

今回はただの終了報告なのでポエムはなしです。なしだけど終わらせたので早速やっていきたいと思います。

22. クラス
前回どこまで進んでたか分かりませんが、クラスの使い方についてのお話からはじめていきます。

using UnityEngine;
using System.Collections;

public class SingleCharacterScript : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
    }
       
    public Stuff myStuff = new Stuff(10, 7, 25);
    public float speed;
    public float turnSpeed;
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;
    
    
    void Update ()
    {
        Movement();
        Shoot();
    }
       
    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
       
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            myStuff.bullets--;
        }
    }
}




using UnityEngine;
using System.Collections;
public class Inventory : MonoBehaviour
{
    public class Stuff
    {
        public int bullets;
        public int grenades;
        public int rockets;
        public float fuel;
        
        public Stuff(int bul, int gre, int roc)
        {
            bullets = bul;
            grenades = gre;
            rockets = roc;
        }
        
        public Stuff(int bul, float fu)
        {
            bullets = bul;
            fuel = fu;
        }
        
        public Stuff ()
        {
            bullets = 1;
            grenades = 1;
            rockets = 1;
        }
    }
    
    // Stuffクラスより
    public Stuff myStuff = new Stuff(50, 5, 5);
    public Stuff myOtherStuff = new Stuff(50, 1.5f);
    void Start()
    {
        Debug.Log(myStuff.bullets); 
    }
}




using UnityEngine;
using System.Collections;

public class MovementControls : MonoBehaviour
{
    public float speed;
    public float turnSpeed;
        
    void Update ()
    {
        Movement();
    }

    void Movement ()
    {
        float forwardMovement = Input.GetAxis("Vertical") * speed * Time.deltaTime;
        float turnMovement = Input.GetAxis("Horizontal") * turnSpeed * Time.deltaTime;
        
        transform.Translate(Vector3.forward * forwardMovement);
        transform.Rotate(Vector3.up * turnMovement);
    }
}




using UnityEngine;
using System.Collections;

public class Shooting : MonoBehaviour
{
    public Rigidbody bulletPrefab;
    public Transform firePosition;
    public float bulletSpeed;   
    private Inventory inventory;
       
    void Awake ()
    {
        inventory = GetComponent<Inventory>();
    }
       
    void Update ()
    {
        Shoot();
    }
   
    void Shoot ()
    {
        if(Input.GetButtonDown("Fire1") && inventory.myStuff.bullets > 0)
        {
            Rigidbody bulletInstance = Instantiate(bulletPrefab, firePosition.position, firePosition.rotation) as Rigidbody;
            bulletInstance.AddForce(firePosition.forward * bulletSpeed);
            inventory.myStuff.bullets--;
        }
    }
}


雑にクラス図をつくってみる。多分こんな感じ、つながりがない……。Unity特有のStart()とかRigidbodyとかそういうのを加えた方がいいのだろうか……。それをやるとごちゃごちゃしてきて何をしたい設計なのか分からなくなる気がする……。まあ、大規模なもの作ったことないからいらぬ心配なんですけどね(笑)。


23. Instantiate

オブジェクトの生成とかにかかわるInstantiateな話。

using UnityEngine;
using System.Collections;
public class UsingInstantiate : MonoBehaviour
{
    public Rigidbody rocketPrefab;
    public Transform barrelEnd;
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            Rigidbody rocketInstance;
            // オブジェクトの生成
            rocketInstance = Instantiate(rocketPrefab, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
            rocketInstance.AddForce(barrelEnd.forward * 5000);
        }
    }
}
using UnityEngine;
using System.Collections;

public class RocketDestruction : MonoBehaviour
{
    void Start()
    {
        // オブジェクトの破壊
        Destroy(gameObject, 1.5f);
    }
}

―と、おまけのデストロイ。


24. Array

なんで後半で配列の話なんだろう。

using UnityEngine;
using System.Collections;

public class Arrays : MonoBehaviour
{
    public GameObject[] players;
    void Start ()
    {
        players = GameObject.FindGameObjectsWithTag("Player");
        for(int i = 0; i < players.Length; i++)
        {
            Debug.Log("Player Number "+i+" is named "+players[i].name);
        }
    }
}

複雑なことをやろうとすると事故るやつだけど、この例だと特に話すことは多分ないです。


25. Invoke
僕の中ではJavaScriptsetTimeoutみたいな認識のやつ。個人的にInvokeって単語はPowerShellの方でよく見かける。あっちはこういう機能なかった気がするけど……。

using UnityEngine;
using System.Collections;
public class InvokeScript : MonoBehaviour
{
    public GameObject target;
    void Start()
    {
        // SpawnObject()
        Invoke("SpawnObject", 2);
    }
    void SpawnObject()
    {
        Instantiate(target, new Vector3(0, 2, 0), Quaternion.identity);
    }
}
using UnityEngine;
using System.Collections;

public class InvokeRepeating : MonoBehaviour
{
    public GameObject target;
    void Start()
    {
        // SpawnObject()
        InvokeRepeating("SpawnObject", 2, 1);
    }

    void SpawnObject()
    {
        float x = Random.Range(-2.0f, 2.0f);
        float z = Random.Range(-2.0f, 2.0f);
        Instantiate(target, new Vector3(x, 2, z), Quaternion.identity);
    }
}

とりあえず該当部分にコメントを入れてはみたものの語ることがない。細かい仕様はリファレンス見ておけばいいような気がする。
MonoBehaviour-Invoke - Unity スクリプトリファレンス
MonoBehaviour-InvokeRepeating - Unity スクリプトリファレンス



26. Enumerations

僕の中ではIDEに任意の文字列を紐づけて補間させるためのタグみたいな認識。次に出てくるSwitch文と併用して使用すると良い感じに使えるって思ってる。IDE使わなければ不要な存在なのでとも思ってたりする……、補間しないし。

using UnityEngine;
using System.Collections;

public class EnumScript : MonoBehaviour 
{
    enum Direction {North, East, South, West};
        void Start () 
    {
        Direction myDirection;
        
        myDirection = Direction.North;
    }   
    Direction ReverseDirection (Direction dir)
    {
        if(dir == Direction.North)
            dir = Direction.South;
        else if(dir == Direction.South)
            dir = Direction.North;
        else if(dir == Direction.East)
            dir = Direction.West;
        else if(dir == Direction.West)
            dir = Direction.East;       
        return dir;     
    }
}


27. Switch Statements

なぜか最後はSwitch文。僕の中ではラベル付きif文。

using UnityEngine;
using System.Collections;

public class ConversationScript : MonoBehaviour 
{
    public int intelligence = 5;
    void Greet()
    {
        switch (intelligence)
        {
        case 5:
            print ("Why hello there good sir! Let me teach you about Trigonometry!");
            break;
        case 4:
            print ("Hello and good day!");
            break;
        case 3:
            print ("Whadya want?");
            break;
        case 2:
            print ("Grog SMASH!");
            break;
        case 1:
            print ("Ulg, glib, Pblblblblb");
            break;
        default:
            print ("Incorrect intelligence level.");
            break;
        }
    }
}

例文のintelligence分岐、文章内容酷すぎるんだけど元ネタあったりするんですかね?

てことで終了です。
f:id:andron:20191009211434p:plain


今回はポエムはなしのでこれで終了です。おそまつさまでした!

ずしゅ

ずしゅらねば生き残れない

突然だけど今日はこれについての雑談をしようと思う。
www.zsh.org
そう "ずしゅ"(ズィーシェル、Z shell、zsh)。ズィーシェルとか横に表記しているけども正しい読み方はずしゅ(僕調べ)だ!誰が何と言おうと「ずしゅ」だ!

ということで、まずこいつが何かですが。

Z shell(ズィーシェル、zsh)はUnixのコマンドシェルの1つである。 対話的なログインコマンドシェルとしても、強力なシェルスクリプトコマンドのインタープリターとしても使うことができる。

zsh は数多くの改良を含んだBourne Shellの拡張版という見方もできる。のみならず、bashkshtcshの非常に有用な機能も一部取り込まれている。また、Windows上でネイティブUnix環境を提供する Interix サブシステム上ではUnix版のソースコードをビルドしてWindows上で使用することができる。

はい、シェル方言の一つです。そのほかの深いことは知らないです。なのでこれから触っていきます。


さわってみる

てなわけでインストールだけしてみます。こまかい便利カスタマイズは多分やさしい有識者的な人がコメント欄でアドバイスしたり、これが最強の設定ファイルだって言ってコメント欄に貼り付けるだろうからそれまでは適当に扱います(他力本願)。

# インストール
$ sudo apt install zsh

# 利用と初回利用メッセージ
$ zsh
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses ---

Aborting.
The function will be run again next time.  To prevent this, execute:
  touch ~/.zshrc

#バージョン確認
% zsh --version
zsh 5.4.2

インストールとかはこれで、初期起動時の画面ですとかカスタマイズとかは.zshrcしましょうってこと書いてます。

んで、カスタマイズはしないって言ったけども自分で細かいカスタマイズしたければArch LinuxWikiだけどこの辺みればいいんじゃないかなって思う。あと使い方とか公式のユーザガイドで(丸投げ)。
Zsh - ArchWiki
A User's Guide to the Z-Shell

結局のところカスタマイズして使わない場合はそんなにbashとそこまで気にしなくても良いような気がする……。

おわり

Bingの使い方

みんなもっとBingを使おう!

つい先月くらいにこのブログにBingと呼ばれるマイクロソフトが提供する検索エンジンからの検索がヒットしていることに気づいたので、Bingの使い方とかいう記事でも書いてみんながBing使ってくれるような宣伝でもしようかと思います。まずBingですが以下のような検索エンジンです。

Bing公式
www.bing.com

Bing(ビング)は、Microsoftが提供する検索エンジンである。「意思決定エンジン」というコンセプトを掲げ、他の検索エンジンとの差別化を図っている。
旧名称はMSN サーチ、Windows Live サーチ、Live サーチがあり、Windows Live サーチは、Windows Liveサービスの一つでもあった。

検索エンジンだったらYahoo!でもGoogleでもいいじゃんってなるんですけど、検索アルゴリズムGoogleと異なります。なので検索結果が異なる。そして、マイクロソフトの検索アルゴリズムですけどコアな部分はオープンソース化されていたりするそうですよ。だからGoogleと違って安心(?)。まあその辺どうでもいいか。
github.com


とかく僕としては皆さんにもっとBingとか使ってほしいなーとか思ったので今日はBing使い方講座(誰得)をやっていきたいと思います。みんなBingを使おう!Bingはいいですよ。フィルターをオフにしてエッチな単語で検索すると精度の高いエッチな画像や動画が……はい……、はてなブログは健全なブログなのでちゃんとした利用法をまとめます。そうしないとこのブログが存続できないのでね。エッチなことを期待してしまったみんなごめんな。このブログの読者層に未成年者いるのかどうかは知らないけども規約でそうなっている以上逆らうことはできないんだ……。僕ははてな様に逆らうことはできないんだ…………。

Bingしよう

ということで一番最初に紹介したリンクを開きましょう!
f:id:andron:20191009111933p:plain
まず全体の画面はこんな感じです。右下あたりにあるメニューから壁紙をダウンロードできます。用途は壁紙用途でしか使えないけどね。


f:id:andron:20191009112125p:plain
壁紙が煩わしかったら右上の設定メニューで壁紙の非表示化ができます。


あとは検索とかですがGoogleに同じく画像で画像検索とかもできます。
f:id:andron:20191009112655p:plain

んで検索結果はPinterestみたいな感じでアーカイブしておくこともできます。まあこの機能Googleも使えますけどね……。

f:id:andron:20191009112821p:plainf:id:andron:20191009112835p:plain



あとは……、Googleに同じく検索時に電卓とか翻訳とか、今日の天気とかそういうのもついてたりします。

f:id:andron:20191009113330p:plainf:id:andron:20191009113337p:plain


最後に個人的にあんま参考にならなかったんだけどヘルプの方も載せておきます。
https://help.bing.microsoft.com/





機能的にはそんな感じですGoogleみたいな隠し機能があるのか知らんです。まあそんな感じだからみんなBingを使おう!