'Unity/수업내용'에 해당되는 글 14건

  1. 2019.06.14 TestGPGS - 구글 플레이에 앱등록하기-2(업적 연동)
  2. 2019.06.13 TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)
  3. 2019.05.24 UGUI Test
  4. 2019.05.09 <Test_SunnyLand>짬뿌END
  5. 2019.05.08 <Test_SunnyLand>짬뿌2
  6. 2019.05.07 <Test_SunnyLand>짬뿌
  7. 2019.05.01 (3,4)ShootAndObjectPooling
  8. 2019.05.01 (2)MoveAnd//한번 더 확인

TestGPGS - 구글 플레이에 앱등록하기-2(업적 연동)

Unity/수업내용 2019. 6. 14. 16:12

단계별 업적은
PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_4, 1, (success) => { //무명함수 내용 });
여기에 1은, 1단계씩 증가한다 라는 뜻

일회성 업적은

Social.ReportProgress(GPGSIds.achievement, 100,
(success) =>
{ //무명함수 내용 });
여기에 100은 완료 0은 미완료

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
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Linq;
using Newtonsoft.Json;
 
public class TestGPGS : MonoBehaviour
{
    public Text txt_Ver;
 
    public Button btn_SignOut;
    public Button btn_achMenu;//업적 메뉴 보기
    public Button btn_ach1;//버튼누르면 몬스터 1킬
    public Button btn_reward;
 
    public Text txt_reward;
    public Text txt_Result;
    public Text txt_kill;//몬스터 처치수
    public Text txt_goldValue;
    public Text txt_gemValue;
 
    private int kill = 0;
 
    private int killMonsterGoal;//몬스터 목표 처치수
    private int killMonsterAchivementStep = 0;//몬스터처치 단계별 업적 달성 단계
    private Dictionary<int, Increment_Achivement> dicIncrement_Achivement;
    private Dictionary<int, Achivement> dicAchivement;
 
    private List<Achivement> achivementsList = new List<Achivement>();
 
    private int gold = 0;
    private int gem = 0;
    private int rewardType;
    private int rewardValue;
 
    void Start()
    {
        this.dicAchivement = new Dictionary<int, Achivement>();
        this.dicIncrement_Achivement = new Dictionary<int, Increment_Achivement>();
 
        var ta1 = Resources.Load<TextAsset>("achivement");
        var arrAchivement = JsonConvert.DeserializeObject<Achivement[]>(ta1.text);
        this.dicAchivement = arrAchivement.ToDictionary(x => x.id);
 
        var ta2 = Resources.Load<TextAsset>("Incremental_achivement");
        var arrIncremental_achivement = JsonConvert.DeserializeObject<Increment_Achivement[]>(ta2.text);
        this.dicIncrement_Achivement = arrIncremental_achivement.ToDictionary(x => x.id);
 
        var arr1 = this.dicAchivement.Where(x => x.Value.achivement_id == 1);
        foreach (var data in arr1)
        {
            this.achivementsList.Add(data.Value);
        }
 
        GPGSManager.Instance.Init();
 
        Debug.LogFormat("Version : {0}", Application.version);
 
        this.txt_Ver.text = Application.version;
 
        GPGSManager.Instance.SignIn((result) =>
        {
            if (result)
            {
                this.txt_Result.text = "로그인 성공";
                Social.ReportProgress(GPGSIds.achievement, 100, (success) =>
                {
                    if (success)
                    {
                        Debug.Log("비긴허 업적 완료");
                    }
                });
            }
            else
            {
                this.txt_Result.text = "로그인 실패";
            }
        });
 
        this.btn_SignOut.onClick.AddListener(() =>
        {
            GPGSManager.Instance.SignOut();
            SceneManager.LoadScene("TestGPGS");
            Debug.Log("로그아웃");
 
        });
 
        this.btn_achMenu.onClick.AddListener(() =>
        {
            Debug.Log("업적 메뉴 띄우기");
            Social.ShowAchievementsUI();
        });
 
        this.btn_ach1.onClick.AddListener(() =>
        {
            this.kill++;
            this.txt_kill.text = string.Format("몬스터 처치 : {0}/{1}", this.kill, this.dicAchivement[killMonsterAchivementStep].goal_value);
 
            if (this.kill == this.dicAchivement[killMonsterAchivementStep].goal_value)
            {
                PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_4, 1, (success) =>
                {
                    Debug.LogFormat("success : {0}", success);
                    if (success)
                    {
                        //보상버튼 활성화
                        this.btn_reward.gameObject.SetActive(true);
                        this.txt_reward.gameObject.SetActive(true);
                        this.rewardType = this.dicAchivement[killMonsterAchivementStep].reward_type;
                        this.rewardValue = this.dicAchivement[killMonsterAchivementStep].reward_val;
                        this.txt_reward.text = string.Format("{0} : {1} 받기", this.rewardType, this.rewardValue);
                    }
                });
                this.killMonsterAchivementStep++;
 
                if (this.kill == this.dicAchivement[this.dicAchivement.Count - 1].goal_value)
                {
                    this.txt_kill.text = string.Format("업적 달성");
                    this.btn_ach1.gameObject.SetActive(false);
 
                }
 
            }
        });
 
        this.btn_reward.onClick.AddListener(() =>
        {
            if (this.rewardType == 0)
            {
                this.gold += this.rewardValue;
            }
            else
            {
                this.gem += this.rewardValue;
            }
 
            this.txt_goldValue.text = this.gold.ToString();
            this.txt_gemValue.text = this.gem.ToString();
            this.btn_reward.gameObject.SetActive(false);
 
        });
    }
 
    private IEnumerator WaitForImage(System.Action onLoaded)
    {
        while (true)
        {
            if (Social.localUser.image != null)
            {
                break;
            }
            yield return null;
        }
 
        onLoaded();
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using System;
 
public class GPGSManager : MonoBehaviour
{
    public static GPGSManager Instance;
 
    void Awake()
    {
        GPGSManager.Instance = this;
    }
 
    public void Init()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
 
 
        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();
    }
 
    public void SignIn(System.Action<bool> onResult)
    {
        Social.localUser.Authenticate((bool success) =>
        {
            onResult(success);
        });
    }
 
    public void SignOut()
    {
        PlayGamesPlatform.Instance.SignOut();
    }
}
 
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
// <copyright file="GPGSIds.cs" company="Google Inc.">
// Copyright (C) 2015 Google Inc. All Rights Reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
 
///
/// This file is automatically generated DO NOT EDIT!
///
/// These are the constants defined in the Play Games Console for Game Services
/// Resources.
///
 
 
public static class GPGSIds
{
        public const string achievement_4 = "CgkImtHoveUREAIQBQ"; // <GPGSID>
        public const string achievement = "CgkImtHoveUREAIQAQ"; // <GPGSID>
        public const string achievement_2 = "CgkImtHoveUREAIQAg"; // <GPGSID>
        public const string achievement_3 = "CgkImtHoveUREAIQAw"; // <GPGSID>
 
}
 
 
cs


1
2
3
4
5
6
7
8
9
public class Increment_Achivement
{
    public int id;
    public string name;
    public int type;
    public int reward_type;
    public int reward_value;
 
}
cs


1
2
3
4
5
6
7
8
9
public class Achivement
{
    public int id;
    public int achivement_id;
    public int goal_value;
    public int reward_type;
    public int reward_val;
 
}
cs


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

TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)  (0) 2019.06.13
UGUI Test  (0) 2019.05.24
<Test_SunnyLand>짬뿌END  (0) 2019.05.09
<Test_SunnyLand>짬뿌2  (0) 2019.05.08
<Test_SunnyLand>짬뿌  (0) 2019.05.07
:

TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)

Unity/수업내용 2019. 6. 13. 17:42

Google Play Console
https://play.google.com/apps/publish/?hl=ko&account=5791372854232521888#AppListPlace

Google APIs
https://console.developers.google.com/apis/dashboard?project=testgpgs-94684386&folder=&organizationId=

//고객센터
https://support.google.com/googleplay/android-developer/answer/113469?hl=ko

//git
https://github.com/playgameservices/play-games-plugin-for-unity

//참고영상-24분 27초
https://youtu.be/UkafEdb342A?t=1467


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
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
 
public class TestGPGS : MonoBehaviour
{
    public Text txt_Ver;
    public Button btn_SignIn;
    public Button btn_SignOut;
    public Text txt_Result;
    public Text txt_LocalUser;
    public Image img_localUserImage;
 
    void Start()
    {
 
        GPGSManager.Instance.Init();
 
        Debug.LogFormat("Version : {0}", Application.version);
 
        this.txt_Ver.text = Application.version;
 
        this.btn_SignIn.onClick.AddListener(() =>
        {
 
            GPGSManager.Instance.SignIn((result) =>
            {
                if (result)
                {
                    this.txt_Result.text = "로그인 성공";
 
                    var id = Social.localUser.id;
                    var name = Social.localUser.userName;
 
                    StartCoroutine(this.WaitForImage(() =>
                    {
                        img_localUserImage.sprite
                        = Sprite.Create(Social.localUser.image, new Rect(00, Social.localUser.image.width, Social.localUser.image.height), new Vector2(00));
                    }));
                    this.txt_LocalUser.text = string.Format("{0}\n{1}", id, name);
                }
                else
                {
                    this.txt_Result.text = "로그인 실패";
                }
            });
        });
 
        this.btn_SignOut.onClick.AddListener(() => 
        {
            PlayGamesPlatform.Instance.SignOut();
            SceneManager.LoadScene("TestGPGS");
            Debug.Log("로그아웃");
 
        });
    }
 
    private IEnumerator WaitForImage(System.Action onLoaded)
    {
        while (true)
        {
            if (Social.localUser.image != null)
            {
                break;
            }
            yield return null;
        }
 
        onLoaded();
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using System;
 
public class GPGSManager : MonoBehaviour
{
    public static GPGSManager Instance;
 
    void Awake()
    {
        GPGSManager.Instance = this;
    }
 
    public void Init()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
 
 
        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();
    }
 
    public void SignIn(System.Action<bool> onResult)
    {
        Social.localUser.Authenticate((bool success) =>
        {
            // handle success or failure
            onResult(success);
        });
    }
 
    public void SignOut()
    {
        PlayGamesPlatform.Instance.SignOut();
    }
}
 
cs


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

TestGPGS - 구글 플레이에 앱등록하기-2(업적 연동)  (0) 2019.06.14
UGUI Test  (0) 2019.05.24
<Test_SunnyLand>짬뿌END  (0) 2019.05.09
<Test_SunnyLand>짬뿌2  (0) 2019.05.08
<Test_SunnyLand>짬뿌  (0) 2019.05.07
:

UGUI Test

Unity/수업내용 2019. 5. 24. 19:55

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.U2D;
 
public class TestUGUI : MonoBehaviour
{
    public SpriteAtlas atlas;
    public RectTransform contents;
    public GameObject listItemGO;
    
    void Start()
    {
        DataManager.Instance.LoadData("Datas/QuestData");
        var missionData = DataManager.Instance.dicData;
        
        for (int i = 0; i < missionData.Count; i++)
        {
            var data = (MissionData)missionData[i];
            var listItem = Instantiate(this.listItemGO, this.contents);
            listItem.transform.localScale = new Vector3(111);
 
            var missionListItem = listItem.GetComponent<MissionListItem>();
            missionListItem.Init(data.id, data.ico_name);
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class MissionListItem : MonoBehaviour
{
    public Image imgIco;
 
    internal void Init(int id, string ico_name)
    {
        var testUGUI = GameObject.FindObjectOfType<TestUGUI>();
        var spriteName =testUGUI.atlas.GetSprite(ico_name);
        this.imgIco.sprite = spriteName;
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
 
public class DataManager : MonoBehaviour
{
    public static DataManager Instance;
    public Dictionary<int, RawData> dicData;
    
    void Awake()
    {
        DataManager.Instance = this;
        this.dicData = new Dictionary<int, RawData>();
    }
 
    public void LoadData(string path)
    {
        var ta = Resources.Load<TextAsset>(path);
        var json = ta.text;
        var arrData = JsonConvert.DeserializeObject<MissionData[]>(json);
 
        foreach(var data in arrData)
        {
            this.dicData.Add(data.id, data);
        }
    }
}
 
cs


1
2
3
4
5
6
7
8
9
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class RawData
{
    public int id;
}
 
cs


1
2
3
4
5
6
7
8
9
10
11
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class MissionData : RawData
{
    public string ico_name;
    public string name;
    public int goal_value;
}
 
cs


:

<Test_SunnyLand>짬뿌END

Unity/수업내용 2019. 5. 9. 17:54


Action 매개변수 넘기기, delegate다시한번 보기


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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using System;
 
public class Test_SunnyLand : MonoBehaviour
{
    #region 캐릭터 컨트롤 맴버 변수
    public GameObject player;
    public Button btnIdle, btnRun, btnJump, btnDir;
    public float jumpPower;
    public Text txt;
 
    private Animator anim;
    private Coroutine routine;
    private string currentAnim;
    private Vector2 jumpVec;
 
    //스위치
    private Coroutine jumpRoutine;
    private Coroutine runRoutine;
    #endregion
 
    #region 맵 컨트롤 맴버 변수
    public Transform[] arrBackGround;
    public Transform[] arrGround;
    public Transform[] arrTree;
    public GameObject[] arrGemGo;
    public float inGameSpeed;
 
    private float dir;
    #endregion
 
    #region 젬 컨트롤 맴버 변수
    public GameObject[] arrUIGem;
    public Transform targetPos;
 
    #endregion
 
    private int count;
    private int i;
 
 
    private void Awake()
    {
        this.anim = this.player.GetComponent<Animator>();
        this.dir = 1;
 
 
    }
 
    private void Start()
    {
        btnDir.onClick.AddListener(() =>
        {
            Debug.Log("방향전환");
            this.dir *= -1;
            this.player.transform.localScale = new Vector3(2 * this.dir, 20);
 
            Debug.LogFormat("방향 : {0}"this.dir);
        });
 
        btnIdle.onClick.AddListener(() =>
        {
            StopAllCoroutines();
            this.Idle();
        });
 
        btnRun.onClick.AddListener(() =>
        {
            this.Run();
        });
 
        btnJump.onClick.AddListener(() =>
        {
            this.Jump();
        });
 
    }
 
    private void Update()
    {
        this.txt.text = this.count.ToString();
        this.player.GetComponent<Player>().onGetGem = (pos) =>
        {
            this.EatGem(pos);
        };
    }
 
    #region 캐릭터 컨트롤
    private void Idle()
    {
        if (this.routine != null)
        {
            StopCoroutine(routine);
        }
 
        this.runRoutine = null;
        this.routine = StartCoroutine(this.IdleImpl());
    }
 
    private void Run()
    {
        if (this.runRoutine != null)
        {
            Debug.Log("이미 뛰고있어");
        }
        else
        {
            this.runRoutine = StartCoroutine(this.RunImpl());
            #region 맵 무브 관련
            StartCoroutine(this.GemMoveImpl());
            StartCoroutine(this.TreeMoveImpl());
            StartCoroutine(this.GroundLoopImpl());
            StartCoroutine(this.BGLoopImpl());
            #endregion
        }
    }
 
    private void Jump()
    {
        if (this.jumpRoutine != null)
        {
            Debug.Log("지금은 점프할 수 없어");
        }
        else
        {
            jumpRoutine = 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)
            {
                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);
                this.jumpRoutine = null;
                break;
            }
            yield return null;
        }
 
 
 
    }
    #endregion
 
    #region 맵컨트롤
 
 
    private IEnumerator BGLoopImpl()
    {
        if (dir > 0)
        {
            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.6f * this.dir)
                    {
                        this.arrBackGround[i].transform.localPosition = new Vector3(-14.2f * this.dir, -9.4412f, 0);
                    }
                }
                yield return null;
            }
        }
        else
        {
            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.6f)
                    {
                        this.arrBackGround[i].transform.localPosition = new Vector3(14.2f, -9.4412f, 0);
                    }
                }
                yield return null;
            }
        }
 
    }
 
    private IEnumerator GroundLoopImpl()
    {
        if (dir > 0)
        {
            while (true)
            {
                for (int i = 0; i < this.arrGround.Length; i++)
                {
                    this.arrGround[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed * this.dir);
                    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;
            }
        }
        else
        {
            while (true)
            {
                for (int i = 0; i < this.arrGround.Length; i++)
                {
                    this.arrGround[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed * this.dir);
                    if (this.arrGround[i].transform.localPosition.x >= 4.8f)
                    {
                        this.arrGround[i].transform.localPosition = new Vector3(-6.4f, -9.6912f, 0);
                    }
                }
                yield return null;
            }
        }
    }
 
    private IEnumerator TreeMoveImpl()
    {
        if (dir > 0)
        {
            while (true)
            {
                for (int i = 0; i < this.arrTree.Length; i++)
                {
                    this.arrTree[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed / 5 * this.dir);
                    if (this.arrTree[i].transform.localPosition.x <= -4 * this.dir)
                    {
                        this.arrTree[i].transform.localPosition = new Vector3(7.9f * this.dir, -14.298f, 0);
                    }
                }
                yield return null;
            }
        }
        else
        {
            while (true)
            {
                for (int i = 0; i < this.arrTree.Length; i++)
                {
                    this.arrTree[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed / 5 * this.dir);
                    if (this.arrTree[i].transform.localPosition.x >= 4)
                    {
                        this.arrTree[i].transform.localPosition = new Vector3(-8.1f, -14.298f, 0);
                    }
                }
                yield return null;
            }
        }
    }
 
    private IEnumerator GemMoveImpl()
    {
        while (true)
        {
 
            for (int i = 0; i < this.arrGemGo.Length; i++)
            {
                this.arrGemGo[i].transform.position += new Vector3(-0.1f, 00* this.inGameSpeed * this.dir;
                if (this.arrGemGo[i].transform.localPosition.x <= -4.8 * this.dir)
                {
                    this.arrGemGo[i].transform.localPosition = new Vector3(6.4f * this.dir, this.arrGemGo[i].transform.localPosition.y, 0);
                    this.arrGemGo[i].SetActive(true);
                }
            }
            yield return null;
        }
    }
    #endregion
 
    #region 젬컨트롤
 
    private void EatGem(Vector3 pos)
    {
        StartCoroutine(this.GetGemMove(this.i, pos));
        this.i++;
        if (this.i >= this.arrUIGem.Length)
        {
            this.i = 0;
        }
    }
 
    private IEnumerator GetGemMove(int i,Vector3 pos)
    {
        Debug.Log(i);
        this.arrUIGem[i].transform.position = Camera.main.WorldToScreenPoint(pos);
        this.arrUIGem[i].SetActive(true);
        Vector3 dir = (targetPos.position - this.arrUIGem[i].transform.position).normalized;
        var dis = Vector3.Distance(targetPos.position, this.arrUIGem[i].transform.position);
 
        while (true)
        {
            this.arrUIGem[i].transform.position += 500 * dir * Time.deltaTime;
            dis -= 500 * Time.deltaTime;
 
            if (dis <= 0)
            {
                this.arrUIGem[i].SetActive(false);
                this.count++;
                break;
            }
            yield return null;
        }
    }
    #endregion
}
 
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class Player : MonoBehaviour
{
    public int count;
    public Vector3 vecCoin;
    
    public System.Action<Vector3> onGetGem;
 
    private void Start()
    {
        Debug.Log("응실행");
    }
 
    public void OnTriggerEnter2D(Collider2D other)
    {
        count += 1;
        other.gameObject.SetActive(false);
        this.onGetGem(other.transform.position);
    }
}
 
cs


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

TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)  (0) 2019.06.13
UGUI Test  (0) 2019.05.24
<Test_SunnyLand>짬뿌2  (0) 2019.05.08
<Test_SunnyLand>짬뿌  (0) 2019.05.07
(3,4)ShootAndObjectPooling  (0) 2019.05.01
:

<Test_SunnyLand>짬뿌2

Unity/수업내용 2019. 5. 8. 18:38



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 Player : MonoBehaviour
{
    public int count;
 
    private void Start()
    {
        Debug.Log("응실행");
    }
 
    public void OnTriggerEnter2D(Collider2D other)
    {
        count += 1;
        other.gameObject.SetActive(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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
 
public class Test_SunnyLand : MonoBehaviour
{
    #region 캐릭터 컨트롤 맴버 변수
    public GameObject player;
    public Button btnIdle, btnRun, btnJump, btnDir;
    public float jumpPower;
    public Text txt;
 
    private Animator anim;
    private Coroutine routine;
    private string currentAnim;
    private Vector2 jumpVec;
 
    //스위치
    private Coroutine jumpRoutine;
    private Coroutine runRoutine;
    #endregion
    #region 맵 컨트롤 맴버 변수
    public Transform[] arrBackGround;
    public Transform[] arrGround;
    public Transform[] arrTree;
    public GameObject[] arrGemGo;
    public Transform[] arrGem;
 
    [Range(15)]
    public float inGameSpeed;
 
    private float dir;
    #endregion
 
 
 
    private void Awake()
    {
        this.anim = this.player.GetComponent<Animator>();
        this.dir = 1;
    }
 
    private void Start()
    {
        btnDir.onClick.AddListener(() =>
        {
            Debug.Log("방향전환");
            this.dir *= -1;
            this.player.transform.localScale = new Vector3(2 * this.dir, 20);
 
            Debug.LogFormat("방향 : {0}"this.dir);
        });
 
        btnIdle.onClick.AddListener(() =>
        {
            StopAllCoroutines();
            this.Idle();
        });
 
        btnRun.onClick.AddListener(() =>
        {
            this.Run();
        });
 
        btnJump.onClick.AddListener(() =>
        {
            this.Jump();
        });
 
    }
 
    private void Update()
    {
        this.txt.text = this.player.GetComponent<Player>().count.ToString();
    }
 
    #region 캐릭터 컨트롤
    private void Idle()
    {
        if (this.routine != null)
        {
            StopCoroutine(routine);
        }
 
        this.runRoutine = null;
        this.routine = StartCoroutine(this.IdleImpl());
    }
 
    private void Run()
    {
        if (this.runRoutine != null)
        {
            Debug.Log("이미 뛰고있어");
        }
        else
        {
            this.runRoutine = StartCoroutine(this.RunImpl());
            #region 맵 무브 관련
            StartCoroutine(this.GemMoveImpl());
            StartCoroutine(this.TreeMoveImpl());
            StartCoroutine(this.GroundLoopImpl());
            StartCoroutine(this.BGLoopImpl());
            #endregion
        }
    }
 
    private void Jump()
    {
        if (this.jumpRoutine != null)
        {
            Debug.Log("지금은 점프할 수 없어");
        }
        else
        {
            jumpRoutine = 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)
            {
                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);
                this.jumpRoutine = null;
                break;
            }
            yield return null;
        }
 
 
 
    }
    #endregion
 
    #region 맵컨트롤
    
 
    private IEnumerator BGLoopImpl()
    {
        if (dir > 0)
        {
            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.6f * this.dir)
                    {
                        this.arrBackGround[i].transform.localPosition = new Vector3(-14.2f * this.dir, -9.4412f, 0);
                    }
                }
                yield return null;
            }
        }
        else
        {
            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.6f)
                    {
                        this.arrBackGround[i].transform.localPosition = new Vector3(14.2f, -9.4412f, 0);
                    }
                }
                yield return null;
            }
        }
 
    }
 
    private IEnumerator GroundLoopImpl()
    {
        if (dir > 0)
        {
            while (true)
            {
                for (int i = 0; i < this.arrGround.Length; i++)
                {
                    this.arrGround[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed * this.dir);
                    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;
            }
        }
        else
        {
            while (true)
            {
                for (int i = 0; i < this.arrGround.Length; i++)
                {
                    this.arrGround[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed * this.dir);
                    if (this.arrGround[i].transform.localPosition.x >= 4.8f)
                    {
                        this.arrGround[i].transform.localPosition = new Vector3(-6.4f, -9.6912f, 0);
                    }
                }
                yield return null;
            }
        }
    }
 
    private IEnumerator TreeMoveImpl()
    {
        if (dir > 0)
        {
            while (true)
            {
                for (int i = 0; i < this.arrTree.Length; i++)
                {
                    this.arrTree[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed / 5 * this.dir);
                    if (this.arrTree[i].transform.localPosition.x <= -4 * this.dir)
                    {
                        this.arrTree[i].transform.localPosition = new Vector3(7.9f * this.dir, -14.298f, 0);
                    }
                }
                yield return null;
            }
        }
        else
        {
            while (true)
            {
                for (int i = 0; i < this.arrTree.Length; i++)
                {
                    this.arrTree[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed / 5 * this.dir);
                    if (this.arrTree[i].transform.localPosition.x >= 4)
                    {
                        this.arrTree[i].transform.localPosition = new Vector3(-8.1f, -14.298f, 0);
                    }
                }
                yield return null;
            }
        }
    }
 
    private IEnumerator GemMoveImpl()
    { 
        while (true)
        {
            for (int i = 0; i < this.arrGem.Length; i++)
            {
                this.arrGem[i].Translate(new Vector3(-0.1f, 00* this.inGameSpeed * this.dir);
                if (this.arrGem[i].transform.localPosition.x <= -4.8 * this.dir)
                {
                    this.arrGem[i].transform.localPosition = new Vector3(6.4f * this.dir, this.arrGem[i].transform.localPosition.y, 0);
                    this.arrGemGo[i].SetActive(true);
                }
            }
            yield return null;
        }
    }
    #endregion
 
}
 
cs


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

UGUI Test  (0) 2019.05.24
<Test_SunnyLand>짬뿌END  (0) 2019.05.09
<Test_SunnyLand>짬뿌  (0) 2019.05.07
(3,4)ShootAndObjectPooling  (0) 2019.05.01
(2)MoveAnd//한번 더 확인  (0) 2019.05.01
:

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

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