C# class

using System;
using System.ComponentModel.DataAnnotations;

namespace Chap3
{
class Car
{
public string name;
public int seats = 4;
}
class MainClass
{
static void Main()
{
Car mycar1 = new Car();
Car mycar2 = new Car();

        //インスタンス
        Console.WriteLine(mycar1 == mycar2);

        mycar1.name = "メイン";
        mycar2.name = "サブ";

        Console.WriteLine(mycar1.name);
        Console.WriteLine(mycar2.name);
    }
}

}

敵を作ってみよう・その2【Unity 2Dアクションの作り方】【初心者入門講座】【ゲームの作り方】#45

今回は敵キャラクターを作ってみましたが、アニメーションがうまく動かなかったです

c# foreach文

<foreach文>

複数の要素をもつものを順番に取り出してくれるループ文

foreach(仮の入れ物 in 取り出し元)

{

}

————————–

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class test : MonoBehaviour

{

    void Start()

    {

        int[] a = {1,2,3,4,5};

        foreach (int i in a)

        {

            Debug.Log(i);

        }

    }

    // Update is called once per frame

    void Update()

    {

    }

}

Unity C# 配列 for文

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class test : MonoBehaviour

{

    void Start()

    {

    int[,,] a = new int[3,4,2];

    for(int i = 0; i < a.GetLength(0); ++i)

    {

        for(int j = 0; j < a.GetLength(1); ++j)

        {

            for(int k = 0; k < a.GetLength(2); ++k)

            {

                a[i,j,k] = i + j + k;//代入

                Debug.Log(“a[“+ i + “,” + j + “,” + k + “]に代入する”);

            }

        }

    }

    }

    // Update is called once per frame

    void Update()

    {

    }

}

C# Unity 多次元配列

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class test : MonoBehaviour

{

    void Start()

    {

    int[,,] a = new int[3,4,2];

    Debug.Log(a.Length);

    Debug.Log(a.GetLength(1));  

    }

    // Update is called once per frame

    void Update()

    {

    }

}

C# Unity 配列

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class test : MonoBehaviour

{

    void Start()

    {

     int[] a = new int[50];

     for(int i = 0; i < a.Length; ++i)

     {

        a[i] = i;

     }

}

    // Update is called once per frame

    void Update()

    {

    }

}

C# 条件分岐

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class test : MonoBehaviour

{

    void Start()

    {

       int a = 1;

       if(a < 0)

       {

            Debug.Log(“通った”);

       }

       else if(a == 1)

       {

        Debug.Log(“真ん中を通った”);

       }

       else

       {

        Debug.Log(“下を通った”);

       }

    }

    // Update is called once per frame

    void Update()

    {

        // 何か追加の処理があればここに記述する

    }

}