'Unity'에 해당되는 글 36건

  1. 2019.05.07 <Test_SunnyLand>짬뿌
  2. 2019.05.07 Unity Editor확장입문 참고
  3. 2019.05.03 setdestination can only be called on an active agent that has been placed on a navmesh
  4. 2019.05.02 유니티 현재의 씬 다시 불러오기
  5. 2019.05.01 (3,4)ShootAndObjectPooling
  6. 2019.05.01 (2)MoveAnd//한번 더 확인
  7. 2019.05.01 (1)BGLoop
  8. 2019.05.01 LayerMask

<Test_SunnyLand>짬뿌

Unity/수업내용 2019. 5. 7. 18:15



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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class Test_SunnyLand : MonoBehaviour
{
    #region 캐릭터 컨트롤 맴버 변수
    public GameObject player;
    public Button btnIdle, btnRun, btnJump;
    public float jumpPower;
 
    private Animator anim;
    private Coroutine routine;
    private string currentAnim;
 
    //스위치
    private bool onJumpMax;
    #endregion
    #region 맵 컨트롤 맴버 변수
    public Transform[] arrBackGround;
    public Transform[] arrGround;
    public Transform[] arrTree;
 
    [Range(15)]
    public float inGameSpeed;
    
    public float dir;
    #endregion
    
    private void Awake()
    {
        this.anim = this.player.GetComponent<Animator>();
    }
 
    private void Start()
    {
        btnIdle.onClick.AddListener(() =>
        {
            StopAllCoroutines();
            this.Idle();
        });
 
        btnRun.onClick.AddListener(() =>
        {
            this.Run();
            this.BGLoop();
            this.GroundLoop();
            this.TreeMove();
        });
 
        btnJump.onClick.AddListener(() =>
        {
            this.Jump();
        });
    }
 
    #region 캐릭터 컨트롤
    private void Idle()
    {
        if (this.routine != null)
        {
            StopCoroutine(routine);
        }
        this.routine = StartCoroutine(this.IdleImpl());
    }
 
    private void Run()
    {
        if (this.routine != null)
        {
            StopCoroutine(routine);
        }
        this.routine = StartCoroutine(this.RunImpl());
    }
 
    private void Jump()
    {
        StartCoroutine(this.JumpImpl());
        StartCoroutine(this.JumpPosImpl());
    }
 
    private IEnumerator IdleImpl()
    {
        Debug.Log("아이들");
        this.anim.Play("player_idle");
        while (true)
        {
            yield return null;
        }
    }
 
    private IEnumerator RunImpl()
    {
        Debug.Log("런");
        this.anim.Play("player_run");
        while (true)
        {
            yield return null;
        }
    }
 
    private IEnumerator JumpImpl()
    {
        if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("player_idle"))
        {
            this.currentAnim = "player_idle";
        }
        else if (this.anim.GetCurrentAnimatorStateInfo(0).IsName("player_run"))
        {
            this.currentAnim = "player_run";
        }
 
        Debug.Log("쩜");
        this.anim.Play("player_jump");
 
        if (this.currentAnim == "player_idle")
        {
            //아이들일땐 제자리 쩜
            yield return new WaitForSeconds(0.5f);
            this.anim.Play("player_idle");
        }
        else if (this.currentAnim == "player_run")
        {
            //아닐땐 달리면서 쩜?
            yield return new WaitForSeconds(0.5f);
            this.anim.Play("player_run");
        }
        yield return null;
    }
 
    private IEnumerator JumpPosImpl()
    {
        //올라가는애
        while (true)
        {
            this.player.transform.position += new Vector3(0this.jumpPower * 4 * Time.deltaTime, 0);
 
            if (this.player.transform.position.y >= this.jumpPower)
            {
                this.onJumpMax = true;
                break;
            }
            yield return null;
        }
 
        while (true)
        {
            this.player.transform.position += new Vector3(0-this.jumpPower * 4 * Time.deltaTime, 0);
 
            if (this.player.transform.position.y <= 0)
            {
                this.player.transform.position = new Vector3(000);
                break;
            }
            yield return null;
        }
    }
    #endregion
 
    #region 맵컨트롤
    private void BGLoop()
    {
        StartCoroutine(this.BGLoopImpl());
    }
 
    private void GroundLoop()
    {
        StartCoroutine(this.GroundLoopImpl());
    }
 
    private void TreeMove()
    {
        StartCoroutine(this.TreeMoveImpl());
    }
 
    private IEnumerator BGLoopImpl()
    {
        while(true)
        {
            for (int i = 0; i < this.arrBackGround.Length; i++)
            {
                this.arrBackGround[i].Translate(new Vector3(0.1f * this.dir, 00* this.inGameSpeed/40);
                if (this.arrBackGround[i].transform.localPosition.x >= 7.61 * this.dir)
                {
                    this.arrBackGround[i].transform.localPosition = new Vector3(-15.36f * this.dir, -9.4412f, 0);
                }
            }
            yield return null;
        }
 
    }
 
    private IEnumerator GroundLoopImpl()
    {
        while (true)
        {
            for (int i = 0; i < this.arrGround.Length; i++)
            {
                this.arrGround[i].Translate(new Vector3(-0.1f * this.dir, 00* this.inGameSpeed);
                if (this.arrGround[i].transform.localPosition.x <= -4.8 * this.dir)
                {
                    this.arrGround[i].transform.localPosition = new Vector3(6.4f * this.dir, -9.6912f, 0);
                }
            }
            yield return null;
        }
    }
 
    private IEnumerator TreeMoveImpl()
    {
        while (true)
        {
            for (int i = 0; i < this.arrTree.Length; i++)
            {
                this.arrTree[i].Translate(new Vector3(-0.1f * this.dir, 00* this.inGameSpeed/5);
                if (this.arrTree[i].transform.localPosition.x <= -4 * this.dir)
                {
                    this.arrTree[i].transform.localPosition = new Vector3(8f * this.dir, -14.298f, 0);
                }
            }
            yield return null;
        }
    }
    #endregion
}
 
cs


찾아볼 것 Unity Editor확장기능(방향전환)

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

<Test_SunnyLand>짬뿌END  (0) 2019.05.09
<Test_SunnyLand>짬뿌2  (0) 2019.05.08
(3,4)ShootAndObjectPooling  (0) 2019.05.01
(2)MoveAnd//한번 더 확인  (0) 2019.05.01
(1)BGLoop  (0) 2019.05.01
:

Unity Editor확장입문 참고

Unity/찾아볼것 2019. 5. 7. 18:04

https://loadofprogrammer.tistory.com/137

'Unity > 찾아볼것' 카테고리의 다른 글

unity editor select list  (0) 2019.08.21
custom Inspector 겹치기 오류  (0) 2019.07.23
<uBMSC> 리듬게임  (0) 2019.05.09
찾아볼것 리스트  (0) 2019.04.12
:

setdestination can only be called on an active agent that has been placed on a navmesh

Unity/찾아본것 2019. 5. 3. 15:27


네브메쉬가 적용된 캐릭터의 좌표를 동적으로 할당할때 생기는 문제


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;
 
public class TestMove : MonoBehaviour
{
    public Button btnStart;
    public GameObject StartPos;
    public GameObject EndPos;
 
    private GameObject hobPrefab;
    private GameObject hob;
    private NavMeshAgent agent;
 
    private bool nope;
 
    private void Awake()
    {
        this.hobPrefab = Resources.Load<GameObject>("Hoverbuggy");
    }
 
    private void Start()
    {
        this.StartGame();
    }
 
    private void StartGame()
    {
        StartCoroutine(this.StartGameImpl());
    }
 
    private IEnumerator StartGameImpl()
    {
        while (true)
        {
            this.btnStart.onClick.AddListener(() =>
            {
                if(!nope)
                {
                    this.nope = true;
 
                    this.hob = Instantiate(hobPrefab);
                    this.agent = this.hob.GetComponent<NavMeshAgent>();
                    this.agent.enabled = false;
                    this.hob.transform.position = new Vector3(this.StartPos.transform.position.x, 0.3f, this.StartPos.transform.position.z);
                    this.agent.enabled = true;
                    this.agent.destination = this.EndPos.transform.position;
                }
            });
            yield return null;
        }
    }
 
}
 
cs


44~49번줄
캐릭터를 인스턴스화 하고, 네브메쉬를 비활성화 한 뒤, 새로운 Vector3를 주고 네브메쉬를 다시 활성화한다.





http://egloos.zum.com/foodybug/v/4102604

'Unity > 찾아본것' 카테고리의 다른 글

Unity Custom Inspector 커스텀 인스펙터  (0) 2019.07.22
<화면 나누기> ViewportRect사용  (0) 2019.06.14
유니티 현재의 씬 다시 불러오기  (0) 2019.05.02
Unity Canvas  (0) 2019.04.24
Animator Length 구하기 API  (0) 2019.04.23
:

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

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
: