목록Programming Language/C# (74)
091
01. 코인먹기-> 코인을 먹었을 때 코인이 z축으로 90도 회전, y축은 10의 위치로 이동하기using System.Collections;using System.Collections.Generic;using UnityEngine;//using UnityEngine.SceneManagement;public class Coin_ggi : MonoBehaviour{ void OnTriggerEnter(Collision col){ if(col.gameObject.name == "Sphere"){ transform.Rotate(0,0,90); transform.position = new Vector3(transform.position.x,10,trans..
01. OnCollisionEnter() == Collider과 Rigidbody가 있어야함-> 충돌이 발생하면 호출되는 메서드를 이용하여 충돌한 두 객체의 이름을 출력 using System.Collections;using System.Collections.Generic;using UnityEngine;public class Collision_ggi : MonoBehaviour{ void OnCollisionEnter(Collision col){ Debug.Log("나:"+gameObject.name); if (col.gameObject.name == "Cylinder") Debug.Log("나와 충돌한 객체:"+col.gameObject.name); ..
* 언급이 없을 경우 기즈모방향이 정방향인 경우를 기준으로 말하고 있습니다. *01. 관계 및 좌표- 부모-자식 관계는 오브젝트 간의 계층적 구조를 통해 동작하며, 부모 오브젝트는 여러 자식 오브젝트를 가질 수 있지만 자식 오브젝트는 단 하나의 부모 오브젝트만을 가질 수 있음- 월드 좌표란 세상 전체에 물건이 어디있는지를 말해주는 것이고, 로컬 좌표란 부모 기준에서 물건이 어디있는지를 말해주는 것 02. tranform 프로퍼티(Property) 및 메서드(Method)* Unity 스크립트에서 transform은 해당 게임 오브젝트에 붙어 있는 Transform 컴포넌트를 바로 가리키는 예약된 변수로-> 게임 오브젝트의 Transform 컴포넌트를 따로 선언하거나 GetComponent로 가져올 필요 ..
* 언급이 없을 경우 기즈모방향이 왼쪽좌표계인 경우를 기준으로 말하고 있습니다. *01. 움직이는 방향을 화살표로 선택하기-> Y,Z축에서 앞뒤로 회전하는 Cube(넓게 판으로 만듦) == X축을 회전축으로 두고 있음using System.Collections;using System.Collections.Generic;using UnityEngine;public class Ground_ggi : MonoBehaviour{ void Update() { float xRotation = transform.localEulerAngles.x; xRotation += Input.GetAxis("Horizontal"); transform.localEulerAngles ..
01. Transform으로 위치값 읽어오기-> Sphere에 붙여서 Cube위에서 z축으로 굴리기using System.Collections;using System.Collections.Generic;using UnityEngine;public class ball_ggi : MonoBehaviour{ float startPoint; float distance; void Start(){ startPoint = transform.position.z; Debug.Log("시작위치"+startPoint); } void Update(){ Debug.Log("움직인 위치"+transform.position.z); dista..
01. Destroy() 사용하기 using System.Collections;using System.Collections.Generic;using UnityEngine;public class Ifstat_ggi : MonoBehaviour { int hp = 20; void OnMouseDown(){ hp -= 10; if(hp- print()와 Debug.Log()는 둘다 콘솔에 메세지를 출력하는데 사용되지만 디버깅에 특화된 Debug.Log()를 사용하는 것을 권장(경고,오류, 정보 등 다양한 필터링 기능을 제공하기 때문에도 더 유용함) - Destroy(gameObject); : 저번 글에서 설명한 GetComponent와 같이 GameObject의 메서..
01. Camera의 원근조절하기using System.Collections;using System.Collections.Generic;using UnityEngine;public class CameraController : MonoBehaviour{ GameObject cam; int fieldDistance = 60; // 게임이 시작될 때 한 번 호출되는 메서드 (초기화) private void Start() { cam = Camera.main.gameObject; // 씬 내에서 메인 카메라의 게임 오브젝트를 찾고 cam에 저장 } // 큐브 오브젝트를 클릭했을 때 호출되는 메서드 private void OnMouseDown() { ..
01. C# script- 유니티에서 복잡한 동적 효과나 상호작용을 추가하기 위해 게임 오브젝트에 컴포넌트로서 추가되어 여러 동작을 제어함//C# Script의 기본코드using System.Collections;using System.Collections.Generic;using UnityEngine;public class Gongguil : MonoBehaviour { // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { }} - using으로 적힌 세줄은 네임스페이스를 추가하는 것, namesp..