unity(51)
-
0408 타겟 포인트로 달려가서 적 때리기
using UnityEngine; using UnityEngine.UI; public class UIGame : MonoBehaviour { public Button btnAttack; public Button btnRun; public Text Hp; private void Start() { } private void Update() { this.Hp.GetComponent().text = this.Hp.ToString(); } } using UnityEngine; public class InGame : MonoBehaviour { public Transform TargetPoint; public UIGame uiGame; public CharacterController player; public Ch..
2021.04.08 -
0407 점수 쌓이는 ui, 랜덤 발생 오브젝트, 클릭하는 곳으로 이동
raycast 쏘는 법 추가 using UnityEngine; public class ItemController : MonoBehaviour { public float dropSpeed = 0; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { this.transform.Translate(0, -0.03f, 0); if (this.transform.position.y < -1.0f) { Destroy(gameObject); } } } using UnityEngine; public class BasketController : MonoBehaviou..
2021.04.08 -
0407 3d 밤송이 던지기
using UnityEngine; public class BamsongiGenerator : MonoBehaviour { public GameObject bamsongiPrefeb; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { //프리팹으로 가지고 게임 오브젝트 생성 var go = Instantiate(bamsongiPrefeb); var ray = Camera.main.ScreenPointToRay(Input.mousePosition); Debug.DrawRay(ray.orig..
2021.04.07 -
0407 애니메이션 구현하기
using UnityEngine; public class PlayerController : MonoBehaviour { Rigidbody2D rigid2D; Animator animator; float jumpForce = 340.0f; float walkForce = 50.0f; float maxWalkSpeed = 2.0f; // Start is called before the first frame update void Start() { this.rigid2D = GetComponent(); this.animator = GetComponent(); } // Update is called once per frame void Update() { //점프한다. if (Input.GetKeyDown(KeyC..
2021.04.07 -
0407 화살 피하기 게임
using UnityEngine; public class ArrowController : MonoBehaviour { GameObject player; // Start is called before the first frame update void Start() { this.player = GameObject.Find("player"); } // Update is called once per frame void Update() { //프레임마다 등속으로 낙하시킨다. transform.Translate(0, -1.0f, 0); //화면 밖으로 나오면 오브젝트를 소멸시킨다. if (transform.position.y < -5.0f) { Destroy(gameObject); } //충돌판정 Vector2 p..
2021.04.07 -
0407 오브젝트 호출, 거리 계산, ui 반영, 사운드 삽입
translate = 게임 오브젝트를 현재 좌표에서 인수 값만큼 이동시키는 메서드 좌표는 절대적(월드 좌표계)이 아닌 상대적(로컬 좌표계), 현재 위치에서 이동한다는 뜻. 스와이프 길이를 조정하려면: 클릭을 시작한 좌표를 startPos와 클릭이 끝난 좌표를 endPos에 대입, GetMouseButtonUp/Down(0) true값 반영 endPos - startPos using UnityEngine; public class CarController : MonoBehaviour { float speed = 0; Vector2 startPos; // Start is called before the first frame update void Start() { } // Update is called once..
2021.04.07