유니티 현재의 씬 다시 불러오기

Unity/찾아본것 2019. 5. 2. 13:41

Docs : https://docs.unity3d.com/ScriptReference/SceneManagement.Scene-buildIndex.html
http://lonpeach.com/2017/01/27/unity3d-how-to-load-current-level-or-scene/


1
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
cs


:

(3,4)ShootAndObjectPooling

Unity/수업내용 2019. 5. 1. 19:05



1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
 
 
public class TestPlayerControll : MonoBehaviour
{
    public Transform bulletSpwanPos;
    public float fireLate;
 
    private float nexFireTime;
 
    public GameObject objPool;
    private GameObject boltPrePab;
    private List<GameObject> bolts;
 
    private void Awake()
    {
        this.bolts = new List<GameObject>();
        this.boltPrePab = Resources.Load<GameObject>("Done_Bolt");//총알 리소스 불러오기
 
        for (int i = 0; i < 10; i++)
        {
            var bolt = Instantiate(this.boltPrePab, this.objPool.transform);
            bolt.SetActive(false);
            bolt.name = $"Done_Bolt ({i})";
            bolts.Add(bolt);
        }
    }
 
    private void Start()
    {
        this.OnClickAttackFire();
    }
 
    private void OnClickAttackFire()
    {
        StartCoroutine(this.OnClickAttackFireImpl());
    }
 
    private IEnumerator OnClickAttackFireImpl()
    {
        while (true)
        {
            if (Input.GetMouseButton(0&& Time.time > this.nexFireTime)
            {
                this.nexFireTime = Time.time + fireLate;
                //오브젝트 풀에 들어있는 Done_Bolt 꺼내기
                this.Shoot();
            }
            yield return null;
        }
    }
 
    private void Shoot()
    {
        StartCoroutine(this.ShootImpl());
    }
 
    private IEnumerator ShootImpl()
    {
        for (int i = 0; i < bolts.Count; i++)
        {
            if (bolts[i].activeSelf == false)
            {
                var usingBolt = bolts[i];
                usingBolt.transform.position = this.transform.position;
                usingBolt.SetActive(true);
                yield return new WaitForSeconds(1);
                usingBolt.SetActive(false);
                break;
            }
        }
        yield return null;
    }
}
 
cs


'Unity > 수업내용' 카테고리의 다른 글

<Test_SunnyLand>짬뿌2  (0) 2019.05.08
<Test_SunnyLand>짬뿌  (0) 2019.05.07
(2)MoveAnd//한번 더 확인  (0) 2019.05.01
(1)BGLoop  (0) 2019.05.01
LayerMask  (0) 2019.05.01
:

(2)MoveAnd//한번 더 확인

Unity/수업내용 2019. 5. 1. 19:04



1
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
:

(1)BGLoop

Unity/수업내용 2019. 5. 1. 19:03



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestBGScrorer : MonoBehaviour
{
    public Transform[] arrGround;
    public float speed = 2f;
 
    private void Update()
    {
        for(int i = 0;  i<this.arrGround.Length;i++)
        {
            this.arrGround[i].Translate(new Vector3(0-0.1f, 0* this.speed);
            if(this.arrGround[i].transform.localPosition.z<=-29.5f)
            {
                this.arrGround[i].transform.localPosition = new Vector3(00, 59f);
            }
        }
    }
}
cs


:

LayerMask

Unity/수업내용 2019. 5. 1. 10:05
1
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestLayerMask : MonoBehaviour
{
    void Start()
    {
        //이름으로 레이어의 넘버를 받음//9
        int layerMask1 = LayerMask.NameToLayer("Shootable");
        Debug.LogFormat("layerMask1 : {0}", layerMask1);
 
        //레이어넘버로 이름 받음//Shootable
        string layerMask2 = LayerMask.LayerToName(layerMask1);
        Debug.LogFormat("layerMask2 : {0}", layerMask2);
 
        //레이어 이름으로 레이어 받아옴//512
        int layerMask3 = LayerMask.GetMask(layerMask2);
        Debug.LogFormat("layerMask3 : {0}", layerMask3);
 
        //2진수 표현
        string layerMask4 = Convert.ToString(layerMask3, 2);
        Debug.LogFormat("layerMask4 : {0}", layerMask4);
 
        //8번 레이어//256
        int layerMask5 = LayerMask.GetMask("Floor");
        Debug.LogFormat("layerMask5 : {0}", Convert.ToString(layerMask5, 2));
 
        //or(8 layer, 9 layer)
        int orLayerMask = layerMask3 | layerMask5;
        Debug.LogFormat("orLayerMask : {0}", Convert.ToString(orLayerMask, 2));
 
        //and(8 layer, 9 layer)
        int andLayerMask = layerMask3 & layerMask5;
        Debug.LogFormat("orLayerMask : {0}", Convert.ToString(andLayerMask, 2));
 
        //not(8 layer)
        int notLayerMask = ~layerMask3;
        Debug.LogFormat("notLayerMask : {0}", Convert.ToString(notLayerMask, 2));
    }
}
 
cs


'Unity > 수업내용' 카테고리의 다른 글

(2)MoveAnd//한번 더 확인  (0) 2019.05.01
(1)BGLoop  (0) 2019.05.01
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링  (0) 2019.04.30
<캐릭터 조작>화면 터치, WASD, 조이스틱  (0) 2019.04.25
HUDTest  (0) 2019.04.25
:

자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링

Unity/수업내용 2019. 4. 30. 23:49



1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class TestLineRenderer : MonoBehaviour
{
 
    private LineRenderer lineRenderer;
    private Light gunLight;
    private LineRenderer gunLine;
    private Ray shootRay;
    private ParticleSystem particle;
    private float time = 0.2f;
    private float range;
    private int shootableMask;
 
    private void Awake()
    {
        this.lineRenderer = this.GetComponent<LineRenderer>();
        this.gunLight = this.GetComponent<Light>();
        this.gunLine = this.GetComponent<LineRenderer>();
        this.particle = this.GetComponent<ParticleSystem>();
        this.shootableMask = LayerMask.GetMask("Shootable");
 
        this.shootRay = new Ray();
    }
    private void Start()
    {
        this.AttackReady();
    }
 
    private void AttackReady()
    {
        StartCoroutine(this.AttackReadyImpl());
    }
 
    private IEnumerator AttackReadyImpl()
    {
        while (true)
        {
            if (Input.GetMouseButtonDown(0))
            {
                this.OnLight();
                this.OnLine();
                this.OnParticle();
                yield return new WaitForSeconds(time);
                this.DisableEffect();
            }
            else if(Input.GetMouseButtonDown(1))
            {
                this.OnLight();
                this.OnLine2();
                this.OnParticle();
                yield return new WaitForSeconds(time);
                this.DisableEffect();
            }
            yield return null;
        }
    }
 
    private void OnParticle()
    {
        this.particle.Stop();
        this.particle.Play();
    }
 
    private void OnLine()
    {
        this.gunLine.enabled = true;
        //어디서부터 어디까지 그릴꺼냐
        this.gunLine.SetPosition(0this.transform.position);
 
        this.shootRay.origin = transform.position;
        this.shootRay.direction = transform.forward;
        RaycastHit shootHit;
 
        if (Physics.Raycast(this.shootRay.origin, this.shootRay.direction, out shootHit, 100f, this.shootableMask))
        {
            this.gunLine.SetPosition(1, shootHit.point);
            Debug.Log(shootHit.transform.name);
        }
        else
        {
            this.gunLine.SetPosition(1, shootRay.origin + shootRay.direction * 100);
        }
        this.gunLine.SetPosition(0this.transform.position);
    }
 
    private void OnLine2()
    {
        this.gunLine.enabled = true;
        //어디서부터 어디까지 그릴꺼냐
        this.gunLine.SetPosition(0this.transform.position);
 
        this.shootRay.origin = transform.position;
        this.shootRay.direction = transform.forward;
        RaycastHit shootHit;
 
        if (Physics.Raycast(this.shootRay.origin, this.shootRay.direction, out shootHit, 100f, this.shootableMask))
        {
            this.gunLine.SetPosition(1, shootHit.point);
            Debug.Log(shootHit.transform.name);
        }
        else
        {
            this.gunLine.SetPosition(1, shootRay.origin + shootRay.direction * 100);
        }
        this.gunLine.SetPosition(0this.transform.position);
    }
 
    private void OnLight()
    {
        this.gunLight.enabled = true;
    }
 
    private void DisableEffect()
    {
        //이펙트 다 끄기
        this.gunLight.enabled = false;
        this.gunLine.enabled = false;
    }
}
 
cs



1
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
48
49
50
51
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestMoveCharacterWASD : MonoBehaviour
{
    private Animator anim;
 
    private void Awake()
    {
        this.anim = GetComponent<Animator>();
    }
 
    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 dir = new Vector3(keyX, 0, keyY).normalized;
            
            this.anim.SetBool("IsWalking", keyX != 0f || keyY != 0f);
            if (dir != Vector3.zero)
            {
                //움직임
                if (!this.anim.GetCurrentAnimatorStateInfo(0).IsName("Move"))
                {
                    this.anim.Play("Move");
                }
                this.transform.position += dir * 6 * Time.deltaTime;
            }
            else
            {
                this.anim.Play("Idle");
            }
            yield return null;
        }
    }
}
 
cs


1
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class TestLookMouse : MonoBehaviour
{
    private int floorMask;
 
    private void Awake()
    {
        this.floorMask = LayerMask.GetMask("Floor");
    }
 
    private void Start()
    {
        this.TrunCharacter();
    }
 
    private void TrunCharacter()
    {
        StartCoroutine(this.TrunChracterImpl());
    }
 
    private IEnumerator TrunChracterImpl()
    {
        while(true)
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
            RaycastHit rayFloorHit;
            if (Physics.Raycast(ray.origin, ray.direction, out rayFloorHit, this.floorMask))
            {
                var mousePos = rayFloorHit.point - this.transform.position;
                mousePos.y = 0f;
 
                this.transform.rotation = Quaternion.LookRotation(mousePos);
            }
            yield return null;
        }
    }
}
 
cs


'Unity > 수업내용' 카테고리의 다른 글

(1)BGLoop  (0) 2019.05.01
LayerMask  (0) 2019.05.01
<캐릭터 조작>화면 터치, WASD, 조이스틱  (0) 2019.04.25
HUDTest  (0) 2019.04.25
<죽어라돌덩이>  (0) 2019.04.12
:

내일 정

잡담 2019. 4. 30. 00:01

===================UI&ICon(다른거 섞여있을 수 있음)===================


https://assetstore.unity.com/packages/2d/gui/icons/casual-ui-138532


https://assetstore.unity.com/packages/2d/gui/icons/samurai-ui-127496


https://assetstore.unity.com/packages/tools/gui/gothic-ui-135882


https://assetstore.unity.com/packages/2d/gui/mobile-fantasy-ui-pro-144776


https://assetstore.unity.com/packages/2d/gui/mobile-fantasy-ui-simple-144827


https://assetstore.unity.com/packages/2d/gui/icons/wooden-ui-93545


https://assetstore.unity.com/packages/2d/gui/bluestone-mobile-ui-44000


https://assetstore.unity.com/packages/2d/gui/warforge-mobile-ui-45809


https://assetstore.unity.com/packages/audio/sound-fx/ui-sounds-futuristic-100706


https://assetstore.unity.com/packages/2d/gui/rpg-mmo-ui-7-114435


https://assetstore.unity.com/packages/tools/gui/ui-gamestrap-28599


https://assetstore.unity.com/packages/2d/gui/icons/force-of-magic-ui-95753


https://assetstore.unity.com/packages/audio/sound-fx/magic-sounds-ui-menu-30039


https://assetstore.unity.com/packages/2d/gui/galactic-storm-ui-74352


https://assetstore.unity.com/packages/2d/gui/frozen-ui-for-ugui-39582


https://assetstore.unity.com/packages/2d/gui/rpg-mmo-ui-for-ngui-18436


https://assetstore.unity.com/packages/2d/gui/icons/fantasy-ui-pack-28633


https://assetstore.unity.com/packages/2d/gui/rpg-mmo-ui-3-for-ugui-32207


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-page03-107957


https://assetstore.unity.com/packages/2d/gui/fantasy-ui-icons-pack-1-2483


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-page02-107887


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-page08-113009


https://assetstore.unity.com/packages/2d/gui/icons/dark-themed-2d-pack-126098


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-page05-109131


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-page06-109609


https://assetstore.unity.com/packages/2d/gui/icons/spellbook-megapack-109615


https://assetstore.unity.com/packages/2d/gui/icons/150-fantasy-skill-icons-83847


https://assetstore.unity.com/packages/2d/gui/fantasy-gui-package-137976


https://assetstore.unity.com/packages/2d/gui/flat-clean-gui-over-200-png-files-110987


https://assetstore.unity.com/packages/2d/gui/icons/magic-potion-bottles-53010


https://assetstore.unity.com/packages/2d/gui/icons/viking-gui-pro-127428


https://assetstore.unity.com/packages/2d/gui/icons/400-magic-skills-139357


https://assetstore.unity.com/packages/2d/gui/icons/clean-flat-buttons-icons-1-96061


https://assetstore.unity.com/packages/2d/gui/icons/clean-flat-buttons-icons-2-126870


https://assetstore.unity.com/packages/tools/gui/canvas-particle-emitter-64134


https://assetstore.unity.com/packages/2d/gui/fantasy-game-interface-21691


https://assetstore.unity.com/packages/2d/gui/icons/2d-rotate-animations-71899


https://assetstore.unity.com/packages/2d/gui/icons/rpg-unitframes-1-powerful-metal-95252



==============버튼======================================

https://assetstore.unity.com/packages/2d/gui/icons/pc-consoles-controller-buttons-icons-pack-85215


https://assetstore.unity.com/packages/2d/gui/icons/xbox-one-playstation-4-buttons-pack-77916


https://assetstore.unity.com/packages/2d/gui/icons/mouse-keyboard-icons-pack-85063


https://assetstore.unity.com/packages/2d/gui/icons/oculus-rift-controller-icons-pack-85974


https://assetstore.unity.com/packages/2d/gui/icons/nintendo-switch-controller-icons-pack-83350



==============사운드=====================================

https://assetstore.unity.com/packages/audio/sound-fx/open-world-rpg-sfx-94307


https://assetstore.unity.com/packages/audio/sound-fx/fantasy-interface-sounds-142508


https://assetstore.unity.com/packages/audio/sound-fx/interface-musical-sounds-pack-143154


https://assetstore.unity.com/packages/audio/sound-fx/interface-sound-effects-84577

'잡담' 카테고리의 다른 글

BPM 체크  (0) 2019.06.04
마인드맵  (0) 2019.05.13
안녕세상아  (0) 2019.03.22
:

<캐릭터 조작>화면 터치, WASD, 조이스틱

Unity/수업내용 2019. 4. 25. 18:22
1
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class TestRayCasAndCollider : MonoBehaviour
{
    public Text txt;
    public Text txtHitPoint;
 
    public GameObject heroGo;
    private Animator heroAnim;
    private float speed = 2;
 
    //조이스틱
    public TestMyJoyStick joystick;
 
    private Coroutine joystickRoutine;
 
    void Awake()
    {
        Debug.Log("어우에읶끄");
        this.heroAnim = this.heroGo.GetComponent<Animator>();
 
    }
 
    void Start()
    {
        Debug.Log("레이케스트 콜라이더 테스트체잿시뱆ㄷ가사");
 
        joystick.OnPointerDownHandler = () =>
        {
            Debug.Log("따따운핸들럴");
            
            StartCoroutine(UpdateJoyStickImple());
        };
        joystick.OnPointerUpHandler = () =>
        {
            StopAllCoroutines();
            Debug.Log("어법핸들럴럴럴");
            this.heroAnim.Play("idle@loop");
        };
    }
 
    private IEnumerator UpdateJoyStickImple()
    {
        while (true)
        {
            var dir = (Vector3.forward * joystick.Vertical + Vector3.right * joystick.Horizontal).normalized;
 
            Debug.LogFormat("{0}", dir);
            if (dir != Vector3.zero)
            {
                //보는방향
                //var rad = Mathf.Atan2(dir.x, dir.z);
                //var dig = Mathf.Rad2Deg * rad;
                //this.heroGo.transform.rotation = Quaternion.Euler(new Vector3(0, dig, 0));
                this.heroGo.transform.rotation = Quaternion.LookRotation(dir);
 
                //움직임
                this.heroAnim.Play("run@loop");
                this.heroGo.transform.position += dir * this.speed * Time.deltaTime;
 
                yield return null;
            }
            else
            {
                this.heroAnim.Play("idle@loop");
            }
 
        }
    }
 
    private void Move(Vector3 pos)
    {
        StopAllCoroutines();
        StartCoroutine(this.MoveImpl(pos));
    }
 
    private IEnumerator MoveImpl(Vector3 pos)
    {
        this.heroAnim.Play("run@loop");
        var dir = (pos - this.heroGo.transform.position).normalized;
        var dis = Vector3.Distance(pos, this.heroGo.transform.position);
        this.heroGo.transform.LookAt(pos);
        while (true)
        {
            if (dis > 0)
            {
                this.heroGo.transform.position += dir * this.speed * Time.deltaTime;
                dis -= this.speed * Time.deltaTime;
                yield return null;
            }
            else
            {
                this.heroAnim.Play("idle@loop");
                this.heroGo.transform.position = pos;
                break;
            }
        }
 
    }
    
    //화면을 누른 좌표로 이동
    private void UpdateMouseInput()
    {
        if (Input.GetMouseButtonUp(0))
        {
            //마우스 스크린 좌표를 화면에 표시
            Debug.LogFormat("마우스 포지션 : {0}", Input.mousePosition);
            this.txt.text = Input.mousePosition.ToString();
 
            //레이 객체를 얻어옴
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
            //화면에 레이를 표시
            Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 5f);
 
            RaycastHit hitInfo;
            if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, 1000))
            {
                Debug.LogFormat("히트 포인트 : {0}", hitInfo.point);
 
                this.txtHitPoint.text = hitInfo.point.ToString();
 
                this.Move(hitInfo.point);
            }
            else
            {
                this.txtHitPoint.text = "빈 공간";
            }
        }
    }
 
    //WASD or 방향키 입력 이동
    private void UpdateKeyInput()
    {
        var keyX = Input.GetAxis("Horizontal");
        var keyY = Input.GetAxis("Vertical");
 
        Vector3 dir = new Vector3(keyX, 0, keyY).normalized;
 
        Debug.LogFormat("{0}", dir);
 
        if (dir != Vector3.zero)
        {
            //보는방향
            //var rad = Mathf.Atan2(keyX, keyY);
            //var dig = Mathf.Rad2Deg * rad;
            //this.heroGo.transform.rotation = Quaternion.Euler(new Vector3(0, dig, 0));
            this.heroGo.transform.rotation = Quaternion.LookRotation(dir);
 
            //움직임
            this.heroAnim.Play("run@loop");
            this.heroGo.transform.position += dir * this.speed * Time.deltaTime;
        }
        else
        {
            this.heroAnim.Play("idle@loop");
        }
    }
 
 
    private void UpdateJoyStickInput()
    {
        var dir = (Vector3.forward * joystick.Vertical + Vector3.right * joystick.Horizontal).normalized;
 
        Debug.LogFormat("{0}", dir);
 
        if (dir != Vector3.zero)
        {
            //보는방향
            //var rad = Mathf.Atan2(dir.x, dir.z);
            //var dig = Mathf.Rad2Deg * rad;
            //this.heroGo.transform.rotation = Quaternion.Euler(new Vector3(0, dig, 0));
            this.heroGo.transform.rotation = Quaternion.LookRotation(dir);
 
            //움직임
            this.heroAnim.Play("run@loop");
            this.heroGo.transform.position += dir * this.speed * Time.deltaTime;
        }
        else
        {
            this.heroAnim.Play("idle@loop");
        }
    }
}
 
cs


'Unity > 수업내용' 카테고리의 다른 글

(1)BGLoop  (0) 2019.05.01
LayerMask  (0) 2019.05.01
자습서1(WASD이동, 마우스 포인트 Look, 라인렌더링  (0) 2019.04.30
HUDTest  (0) 2019.04.25
<죽어라돌덩이>  (0) 2019.04.12
: