모바일 게임 프로그래밍 3주차 소스코드 정리

2025. 3. 18. 15:41모바일 게임 프로그래밍/소스코드

반응형
using UnityEngine;
public class CubeScripts_jsy : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        transform.Translate(0, 0, 1);
        gameObject.AddComponent<Rigidbody>();
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}
// 3주차 실습1
using UnityEngine;

public class SphereScripts_jsy : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        transform.Translate(3, 0, 0);
        gameObject.AddComponent<Rigidbody>();
    }

    // Update is called once per framed
    void Update()
    {
        
    }
}
console 탭에 10을 출력
using System.Runtime.InteropServices;
using UnityEngine;

public class CubeScripts_jsy : MonoBehaviour
{
    //변수선언
    int myAge;
    //use this for initialization
    void Start()
    {
        myAge = 10;
        print(myAge);
    }

    // Update is called once per frame
    void Update()
    {

    }
}
//데이터 타입과 값 입력
//변수의 접근 범위
using System.Runtime.InteropServices;
using UnityEngine;

public class CubeScripts_jsy : MonoBehaviour
{
    //변수선언
    int speed = 10;
    float myValue = 34.5f;
    string myName = "jsy";
    public bool IsAlive = true;

    void Start()
    {
        float myValue = 40.5f;
        print(speed);
        print(myName);
        print(myValue);
        print(IsAlive);
    }

    // Update is called once per frame
    void Update()
    {

    }
}
.[약자_scripts2]스크립트를 생성하고 Sphere에 부착 후  
아래 소스를 실행했을 경우의 실행결과를 캡처하시오. 또한, ?,??,???,????,?????에 
왼쪽 변수의 접근 범위를 쓰시오.(변수의 접근범위: public, private, local 중 하나임)

//실습2
using System.Runtime.InteropServices;
using UnityEngine;

public class jsy_scripts2 : MonoBehaviour
{
    public int aa = 1000; //public
    float bb = 4.0f; // private
    public bool Ist = false; // pubilc
    public string name1 = "정상연"; // public
    
    void Start()
    {
        bool Ist = true; // local(지역변수)
        print (Ist);
        print (name1);
        print (bb);
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
// update()함수 활용

using System.Runtime.InteropServices;
using System.Security.Cryptography;
using UnityEngine;

public class ShowUpdate_jsy : MonoBehaviour
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //print("hello, 정상연");
        transform.Translate(0, 0, 1);
    }
}
// update()함수 활용
// 초당 이동거리를 자동으로 계산하기

using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Threading;
using UnityEngine;

public class ShowUpdate_jsy : MonoBehaviour
{
    public float speed = 1.0f;
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(0, 0, speed * Time.deltaTime);
    }
}

//1초에 2m을 이동 시키고 싶으면
//transform.Translate(0,0, ?);

//예1) 1초에 2m 이동: 1초에 10프레임을 실행하면 프레임마다 2m를 10번으로 나눠서 이동
//Time.deltaTime => 0.1
//이동거리: ?? = 2m이동

//예2) 1초에 2m 이동: 1초에 5프레임을 실행하면 프레임마다 2m를 5번으로 나눠서 이동
//Time.deltaTime => 0.2
//이동거리: ??? = 2m이동
//? : 2.0f
//?? : 0.2+ 0.2 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2 + 0.2  = 2m이동
//??? : 0.4 + 0.4 + 0.4 + 0.4 + 0.4 = 2m 이동
// 3주차 실습4
//내가 원하는 속도로 위아래를 왔다가 갔다 할 수 있도록
using UnityEngine;

public class SphereScripts_jsy : MonoBehaviour
{
    public float speed = 1.0f;
    void Start()
    {

    }


    void Update()
    {
        transform.Translate(0, speed * Time.deltaTime, 0);
    }
}
//실습5
//(가)실행하면 Cylinder가 Y축으로 2만큼 올라가도록 소스를 채우시오.
//(나)~(라) public 변수 3개를 지정하여, 인스펙터창에서 값을 변경하면 
//Cylinder가  X축, Y축, Z축으로 움직이도록 소스를 채우시오. 실행화면도 올립니다.

using System.Security.Cryptography;
using UnityEngine;

public class jsy_test : MonoBehaviour
{
    public float sp1;
    public float sp2;
    public float sp3;
    void Start()
    {
        transform.Translate(0, 2, 0);
    }

    void Update()
    {
        transform.Translate
            (sp1 * Time.deltaTime,sp2 * Time.deltaTime,
              sp3 * Time.deltaTime);  
    }
}
//실습6
using System.Threading;
using UnityEngine;

public class jsy_test2 : MonoBehaviour
{
    
    float speed = -0.2f;
    void Start()
    {
        
    }

    void Update()
    {
        transform.Translate(0, speed * Time.deltaTime, 0);
    }
}
//실습7

using System.Threading;
using UnityEngine;

public class jsy_test2 : MonoBehaviour
{

    float x1 = 0.2f; // private
    public float y1 = 0.2f; // public
    void Start()
    {
        

    }

    void Update()
    {
        float z1 = 0.2f; // local
        transform.Translate(x1 * Time.deltaTime,
            y1 * Time.deltaTime, z1 * Time.deltaTime);
    }
}