카테고리 없음

2018.04.10 수업내용 (점프, Delegate)

일등하이 2018. 5. 15. 21:44
반응형
Rigidbody를 이용한 점프 
Rigidbody없이 점프 

System.Action
delegate
System.Event, System.EventHandler

안드로이드 스튜디오 설치 

tortoise SVN client 설치 

Event-driven 방식
옵져버 패턴 


--- 남은 시간동안 해봤으면 하는 내용들 

[2D]
parabola algorithm (앵그리버드)
2D Tile map (a * 알고리즘, 4방향)
2.5D Tile Map (빌딩 게임)
Running Game (쿠키런)
카드 게임 

[3D]
unity navmeshagent(캐릭터컨트롤)
Qualcomm Framework를 이용한 AR 제작 
Oculus Framework를 이용한 VR 제작 (박스 VR구매 5천원)
3D러닝 게임 (슈퍼배드미니언)
parabola algorithm (야구, 골프게임 시뮬)

[기타]
자이로센서를 이용한 게임 제작 (Doodle Jump)
가상패드 (조이스틱)을 사용한 게임 제작 


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class BirdOrc : MonoBehaviour {
 
    public bool isGround;
 
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
 
    private void OnCollisionEnter2D(Collision2D collision)
    {
        
    }
 
    private void OnCollisionStay2D(Collision2D collision)
    {
        if (collision.transform.tag == "Ground")
        {
            this.isGround = true;
        }
    }
 
    private void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.transform.tag == "Ground")
        {
            this.isGround = 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class JumpWithoutRigidbody : MonoBehaviour
{
    public Animation birdOrcAnim;
    public UIGame uiGame;
 
    [SerializeField]
    private float maxJumpHeight = 5f;
 
    private bool isGrounded;
    private Vector2 groundPos;
    private Vector2 dir;
 
    [SerializeField]
    private float gravity = 9.8f;
 
    void Start()
    {
        //this.uiGame.onTouchJumpButton = OnTouchJumpButton;
        //this.uiGame.onJumpHandler += new System.EventHandler(OnJumHandler);
        this.uiGame.onJump += OnTouchJumpButton;
    }
 
    //private void OnJumHandler(object sender, System.EventArgs e)
    //{
    //    var args = (UIGameArgs)e;
    //    Debug.LogFormat("OnJumHandler : {0}, {1}", sender, args.message);
    //}
 
    private void OnTouchJumpButton(UIGameArgs args)
    {
        Debug.LogFormat("OnTouchJumpButton: {0}", args.message);
    }
 
 
    // Update is called once per frame
    void Update()
    {
        if (!this.isGrounded)
        {
            this.dir.y -= this.gravity * Time.deltaTime;
        }
 
        this.birdOrcAnim.transform.Translate(this.dir * Time.deltaTime);
 
        this.isGrounded = this.birdOrcAnim.transform.position.y <= 0;
 
        if (isGrounded)
        {
            this.birdOrcAnim.transform.position = Vector3.zero;
        }
    }
 
    public void Jump()
    {
        if (this.isGrounded)
        {
            this.dir.y = this.maxJumpHeight;
        }
    }
 
    
 
 
}
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class JumpWithRigidbody : MonoBehaviour {
 
    public BirdOrc birdOrc;
    public float vy = 1;
    public float gravityScale = 1;
    private Rigidbody2D birdOrcRigidbody2d;
 
    // Use this for initialization
    void Start () {
        birdOrcRigidbody2d = this.birdOrc.GetComponent<Rigidbody2D>();
        
    }
 
 
    // Update is called once per frame
    void Update () {
        this.birdOrcRigidbody2d.gravityScale = this.gravityScale;
    }
 
    public void Jump()
    {
        if (birdOrc.isGround)
        {
            //this.birdOrc.isGround = false;
            this.birdOrcRigidbody2d.AddForce(Vector3.up * vy, ForceMode2D.Impulse);
        }
    }
 
    private void OnGUI()
    {
        if (GUILayout.Button("Jump", GUILayout.Width(100), GUILayout.Height(80)))
        {
            this.Jump();
        }
    }
}
 
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class UIGameArgs : System.EventArgs
{
    public string message;
}
 
public class UIGame : MonoBehaviour {
 
    //public event System.EventHandler onJumpHandler;
 
    public delegate void onTouchJumpButton(UIGameArgs args);
    public onTouchJumpButton onJump;
    
    
    //public System.Action<UIGameArgs> onTouchJumpButton;
 
 
 
 
 
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
 
    public void OnTouchJumpButton()
    {
        var args = new UIGameArgs();
        args.message = "안녕하세요 나 점프했어요!";
 
        //onTouchJumpButton(args);
 
        //onTouchJumpButton();
 
        onJump(args);
 
        //var arg = new UIGameArgs();
        //arg.message = "안녕하세요 나 점프 했어요!";
        //this.onJumpHandler(this, arg);
    }
 
    public void ActiveJumpButton()
    {
 
    }
 
    public void DeActiveJumpButton()
    {
 
    }
 
    private void OnGUI()
    {
        if (GUILayout.Button("Jump", GUILayout.Width(100), GUILayout.Height(80)))
        {
            this.OnTouchJumpButton();
        }
    }
}
 
cs


Jump with rigidbody
Jump without rigidbody




System.Action
delegate
System.EventHandler
event





반응형