(2)MoveAnd//한번 더 확인
Unity/수업내용 2019. 5. 1. 19:041 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | using System.Collections; using System.Collections.Generic; using UnityEngine; [System.Serializable] public class Boundary { public float xMin; public float xMax; public float zMin; public float zMax; } public class TestMoveShip : MonoBehaviour { public float speed; public float tilt; public Boundary boundary; private void Start() { this.Move(); } private void Move() { StartCoroutine(this.MoveImpl()); } private IEnumerator MoveImpl() { while (true) { float keyX = Input.GetAxisRaw("Horizontal");//키 받아서 float keyY = Input.GetAxisRaw("Vertical");//키 받아서 Vector3 movement = new Vector3(keyX, 0.0f, keyY);//움직여(아마 방향) GetComponent<Rigidbody>().velocity = movement * speed;//리짓바디를 움직임 GetComponent<Rigidbody>().position = new Vector3(Mathf.Clamp(GetComponent<Rigidbody>().position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(GetComponent<Rigidbody>().position.z, boundary.zMin, boundary.zMax));//리짓바디의 움직임은 Clamp 를 사용해서 최대갈 수 있는 공간을 정한다. GetComponent<Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent<Rigidbody>().velocity.x * -tilt);//캐릭터가 이동할때 회전각에 맞춰서 리짓바디를 돌린다. yield return null; } } } | cs |
'Unity > 수업내용' 카테고리의 다른 글
<Test_SunnyLand>짬뿌 (0) | 2019.05.07 |
---|---|
(3,4)ShootAndObjectPooling (0) | 2019.05.01 |
(1)BGLoop (0) | 2019.05.01 |
LayerMask (0) | 2019.05.01 |
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링 (0) | 2019.04.30 |