반응형 앱 만들기402 유니티 = 마우스로 캐릭터 이동시키기 // Update is called once per frame void Update() { // 마우스가 눌렸을때 if (Input.GetMouseButton(0)) { // PC 상의 좌표점을 게임상의 월드 좌표점으로 변경한다. Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); // 현재 좌표점에서 마우스 클릭한 좌료점으로 3번째 인수 크기만큼 이동시킨다. tr.position = Vector2.MoveTowards(tr.position, mousePosition, Time.delt.. 2019. 7. 15. 유니티 = 키보드 & 조이스틱 4방향 움직이기. // Update is called once per frame void Update() { // 키보드 & 조이스틱에서 4방향으로 움직이기 float x = Input.GetAxis("Horizontal")* 0.01f; float y = Input.GetAxis("Vertical") * 0.01f; tr.Translate(new Vector2(x,y)); //Translate : 현재 좌표점에서 입력된 좌표점 만큼 좌우로 이동함 2019. 7. 14. 유니티 = 키보드 왼쪽/오른쪽 화살표 눌러서 캐릭터 이동하기 // Update is called once per frame void Update() { // 오른쪽 화살표 if (Input.GetKey(KeyCode.RightArrow)) { tr.position = new Vector2(tr.position.x + 0.01f, 0); } // 왼쪽 화살표 if (Input.GetKey(KeyCode.LeftArrow)) { tr.position = new Vector2(tr.position.x - 0.01f, 0); } } 2019. 7. 14. 유니티 안드로이드 백키 종료 유니티 안드로이드 백키 종료 //안드로이드 백키 종료 if (Application.platform == RuntimePlatform.Android) if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } 2019. 2. 16. Flappy Bird 에서 Bird 점프시 Z축 각도 변경시키기. Flappy Bird 에서 Bird 점프시 Z축 각도 변경시키기. void Update() { if(Input.GetKeyDown(KeyCode.Space) && transform.position.y = 0.0f); //수평에 따라 애니메이션 변화. } public void ApplyAngle() { // 현재 속도, 상대 속도로부터 진행되고 있는 각도를 구한다. float targetAngle = Mathf.Atan2(rd2D.velocity.y, relativeVelocityX) * Mathf.Rad2Deg; // 회전 애니메이션을 스무딩. angle = Mathf.Lerp(.. 2019. 2. 13. 유니티 키 입력하기 1. 키보드 입력하기 void Update() { if(Input.GetKeyDown(KeyCode.Space) && transform.position.y = 0.0f); } 2. buttonName 입력하기 void Update() { if(Input.GetButtonDown("Fire1") && transform.position.y = 0.0f); } buttonName은 하기메뉴에서 키보드와 매핑되어있음. 예) "Fire1 = left Crtl" E.. 2019. 2. 13. 유니티 오브젝트 스크롤 시키기. 유니티 오브젝트 스크롤 시키기. public class ScrollObject : MonoBehaviour{ public float speed = 1.0f; public float startPosition; public float endPostion; // Update is called once per frame void Update() { // 매 프레임마다 X포지션으르 조금씩 이동시킨다. transform.Translate(-1 * speed * Time.deltaTime, 0, 0); if (transform.position.x 2019. 2. 12. 유니티 - 스와이프 길이 구하기 유니티 - 스와이프 길이 구하기 using System.Collections;using System.Collections.Generic;using UnityEngine; public class Car : MonoBehaviour{ Vector2 startPos; Vector2 endPos; float swipeLength; float speed; // Update is called once per frame void Update() { // 스와이프 길이를 구한다. // 마우스를 클릭했을때 혹은 폰 화면을 터치하면. if (Input.GetMouseButtonDown(0)) { this.startPos = Input.mousePosition; }else if (Input.GetMouseButtonUp(0.. 2019. 2. 7. 유니티 - animation event has no function name specified 이벤트 오류시 하기이미지 애니메이션 타임라인의 마커(Animation Event)를 삭제한다. * 즉, 등록된 이벤트에 연결된 함수가 없기에 발생하는 문제임. 2019. 2. 4. 이전 1 ··· 41 42 43 44 45 다음 반응형