LoginSignup
6
7

More than 5 years have passed since last update.

Unityプログラミング基礎演習 (変数編)

Posted at

Unityプログラミング基礎 (変数からclassまで)
の演習編です。
Debug.Log();によってコンソールに何が出力されるか考えてください。
答え合わせの方法
Startメソッドの中に問題をコピー&ペーストして再生します

答え合わせの方法
using UnityEngine;
using System.Collections;

public class BallScript2 : MonoBehaviour {

    // Use this for initialization
    void Start () {
        // ここに問題をコピー&ペーストしてゲームを再生する
    }
}

まず例題です。

例題1
int x = 1;
Debug.Log(x); //コンソールに1を出力

それではどうぞ

Level1

問題1
int hp = 10;
hp = 2;
Debug.Log(hp); 
問題2
int x = 2;
int y = 3;
int answer = x + y; 
Debug.Log(y - x); 
Debug.Log(answer); 
Debug.Log(answer * x);
問題3
int x = 10;
int y = 3;
float z = 2.0f
int answer = x/y; 
Debug.Log(answer); 
Debug.Log(x % answer); 
Debug.Log(answer / z);
問題4
int x = 10;
x = x + 2;
Debug.Log(x);
x += 3;
Debug.Log(x);
x = 1;
x++;
Debug.Log(x);
問題5
int x = 10;
x = x - 2;
Debug.Log(x);
x -= 3;
Debug.Log(x);
x *= 2;
Debug.Log(x);
x--;
Debug.Log(x);

Level2

例題2
bool check = true;
if(check){
    Debug.Log("Check is true");
}else{
    Debug.Log("Check is false");
}
//コンソールに"Check is true"を出力
問題6
int x = 2;
int y = 3;
if(x < y){
    Debug.Log("1");
}else{
    Debug.Log("2");
}
問題7
int x = 2;
if(x < 0){
    Debug.Log("1");
}else if(x == 0){
     Debug.Log("2");
}else{
    Debug.Log("3");
}
問題8
int x = 2;
int y = -2;
if(x > 0 && y > 0){
    Debug.Log("1");
}
if(x > 0 || y > 0){
    Debug.Log("2");   
}
if(x != y){
     Debug.Log("3");   
}
6
7
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
6
7