4주차 유니티 프로그래밍

2024. 9. 25. 11:43게임 프로그래밍/유니티 프로그래밍

반응형

실습6이 시험에 나올 확률이 있음

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Var_jsy : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        // 실습1

        //int num1 = 2024001910;
        //print(("학번은") + (num1));
        // int no1 = 2, no2 = 6;
        //  print(("no1+no2=") + (no1 + no2));

        //실습2

        //int num;
        //num = 10;
        //print(num);
        //float fnum;
        //fnum = 10.2f;
        //print(fnum);

 

        //실습3
        //float num1 = (23.1f);
        //print(("실수형출력") + (num1));
        //float no1 = 2.1f, no2 = 6.3f;
        //print(("no2-no1=")+(no2 - no1));

    }

실습1
실습2
실습3

실습4

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Var_jsy : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int myage = 10;
int myTel = 20;
string name = "su";
float mySpeed;
bool isAlive = true;
mySpeed = myage;
print(("나이는?") + (myage));
print(("전화번호는?") + (myTel));
print(("이름은?") + (name));
print(("속도는?") + (mySpeed));
print(("건강해?") + (isAlive));
}

실습4

실습5

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Var_jsy : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int num1, num2, num3, sum;
float average;
num1 = 5;
num2 = 20;
num3 = 30;
sum = (num1 + num2 + num3);
average = (sum / 3);
print(("총합은?") + (sum));
print(("평균은?") + (average));
}
// Update is called once per frame
void Update()
{

실습5

 
}
}

실습6

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Var_jsy : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
bool true_or_false = true;
print(("참일까 거짓일까?") + (!true_or_false));
print(("참일까 거짓일까?") + (true_or_false));
print("!는 반대를 나타냅니다");
}
// Update is called once per frame
void Update()
{
 
}
}
실습6

실습6 변형

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Var_jsy : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
bool true_or_false = true;
print(("참일까 거짓일까?") + (true_or_false));
print(("참일까 거짓일까?") + (!true_or_false));
print("!는 반대를 나타냅니다");
}

실습6 변형

실습7

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int inc = 20;
int inc1;
inc1 = inc++;
print("inc++=" + inc1);
print("inc=" + inc);
inc = --inc;
print("--inc=" + inc1);
print("inc=" + inc);
}
}

실습7

실습7 변형

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int inc = 20;
int inc1;
inc1 = ++inc;
print("++inc=" + inc1);
print("inc=" + inc);
inc = inc--;
print("inc--=" + inc1);
print("inc=" + inc);
}
}

실습7 변형


실습8

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
string connect1 = "연결하자";
int inc1 = 3;
int inc2 = 6;
print(connect1 + inc1 + inc2);
print(connect1 + (inc1 + inc2));
}
void Update()
{
}
}
실습8

실습9 코드1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
int myMon = 100;

 

print(myMon);
}
void Update()
{
int myMon = 100;
print(myMon);
}
}
9-1

실습9 코드2

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
int myMon = 100;
void Start()
{
print(myMon);
}
void Update()
{
print(myMon);
}
}
9-2

실습10

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
public string s1 = "하나";
public int k1 = 1;
float f1 = 21.2f;
void Start()
{
int n2 = 2;
print((s1)+(k1)+(f1)+(n2));
print((s1) + (f1 + n2 + k1));
}
void Update()
{
}
}

실습10

 

각 변수의 접근 제한자를 정리

  1. s1: public - 외부에서 접근 가능.
  2. k1: public - 외부에서 접근 가능.
  3. f1: private - 클래스 내에서만 접근 가능.
  4. n2: local - Start 메서드 내에서만 유효, 외부에서 접근 불가능.