본문 바로가기

Unity/Input

(4)
[Unity] Debug.Log를 화면에 보여주기 (GUILayout) Debug.Log를 화면에 보여주기 (GUILayout) using System.Collections; using System.Collections.Generic; using UnityEngine; public class MyLog : MonoBehaviour { string myLog; Queue myLogQueue = new Queue(); private GUIStyle guiStyle = new GUIStyle(); void Start() { guiStyle.fontSize = 20; Debug.Log("MyLog Start"); } void OnEnable() { Application.logMessageReceived += HandleLog; } void OnDisable() { Applicati..
[Unity] 버튼에 마우스 클릭 이벤트 사용하기 [Unity] 버튼에 마우스 클릭 이벤트 사용하기 using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { //Make sure to attach these Buttons in the Inspector public Button m_YourFirstButton, m_YourSecondButton, m_YourThirdButton; void Start() { //Calls the TaskOnClick/TaskWithParameters/ButtonClicked method when you click the Button m_YourFirstButton.onClick.AddListener(TaskOnClick); m_YourSe..
[Unity] 마우스 클릭 지점으로 이동 [Unity] 마우스 클릭 지점으로 이동 using UnityEngine; public class ClickMove : MonoBehaviour { private Ray ray; private RaycastHit hit; private Vector3 movePos = Vector3.zero; private Transform tr; private Animator anim; // Use this for initialization void Start () { tr = GetComponent(); anim = GetComponent(); } // Update is called once per frame void Update () { ray = Camera.main.ScreenPointToRay(Input.mou..
[Unity] 캐릭터 좌우로 움직이기 (RigidBody) [Unity] 캐릭터 좌우로 움직이기 (RigidBody) [Header("속도 관련 변수")][Range(0,1)] [SerializeField] float moveSpeed; //강제로 인스펙터 창에 띄울 수 있음 Rigidbody myRigid; // Update is called once per frame void Update () { if (Input.GetAxisRaw("Horizontal") != 0) // 왼쪽 -1, 오른쪽 1 { Vector3 moveDir = new Vector3(0, 0, Input.GetAxisRaw("Horizontal")); myRigid.AddForce(moveDir * moveSpeed); } }