본문 바로가기
유니티

1945Game

by SUGI_ 2023. 7. 18.

01 배경 스크롤

Mesh Renderer - Offset의 값을 이용함.

 

텍스처 - Unity 매뉴얼

텍스처는 게임 오브젝트를 덮거나 래핑하는 이미지 또는 동영상 파일로 시각적 효과를 만들어 냅니다. 이 페이지에서는 텍스처 관리에 필요한 프로퍼티에 대해 자세하게 다룹니다.

docs.unity3d.com

Background  설정

public class BackGround : MonoBehaviour
{
    [Header("스크롤이동속도")]
    [SerializeField] float scrollSpeed = 0.01f;
    Material myMaterial;

    void Start()
    {
        myMaterial = GetComponent<Renderer>().material;    
    }
    void Update()
    {
        float newOffsetY = myMaterial.mainTextureOffset.y + scrollSpeed * Time.deltaTime;
        Vector2 newOffset = new Vector2(0, newOffsetY);

        myMaterial.mainTextureOffset = newOffset;
    }
}

02 Player 이동 애니메이션

합쳐져 있는 이미지를 Sprite - Multiple를 통해 나눠준다
bool 값으로 처리

public class Player : MonoBehaviour
{
    [SerializeField] float moveSpeed = 5;
    [SerializeField] GameObject bullet = null; //null 써놓으면 넣지 않아도 오류안뜸
    [SerializeField] Transform pos = null;

    Animator ani;

    void Start()
    {
        ani = GetComponent<Animator>();
    }

    void Update()
    {
        float moveX = moveSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
        float moveY = moveSpeed * Time.deltaTime * Input.GetAxis("Vertical");

        if(Input.GetAxis("Horizontal") >= 0.5f)
        {
            ani.SetBool("right", true);
        }
        else
        {
            ani.SetBool("right", false);
        }

        if(Input.GetAxis("Horizontal") <= -0.5f)
        {
            ani.SetBool("left", true);
        }
        else
        {
            ani.SetBool("left", false);
        }

        if(Input.GetAxis("Vertical") >= 0.5f)
        {
            ani.SetBool("up", true);
        }
        else
        {
            ani.SetBool("up", false);
        }

        transform.Translate(moveX, moveY, 0);
    }
}

03 Bullet

space 누르면 발사 가능 -> Instantiate

 

화면 나가면 삭제해주기

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=happybaby56&logNo=221360560066 

 

[유니티] OnBecameVisible(), OnBecameInvisible(), OnWillRenderObject()

void OnBecameVisible() {  }  void OnBecameInvisible() {  }  void OnWillRenderObject() {  }  우선...

blog.naver.com

    private void OnBecameInvisible()
    {
        Destroy(gameObject);
    }

 

04 Monster 

InvokeRepeating을 사용하여 호출 - Instantiate

 

05 Monster Bullet

처음 시작할때 플레이어의 방향으로

 

<참고> 

Tag로 플레이어 찾는 방법 GameObject.FindGameObjectWithTag("Player");

https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html

https://curioso365.tistory.com/106

비활성화, 자식오브젝트 찾는 방법

https://prosto.tistory.com/147

 

 

방향 벡터 - 벡터의 정규화(normalized) 유니티

더보기 "유니티 방향 벡터" "유니티 노말라이즈드" 오브젝트 균일한 이동을 위하여 벡터의 정규화가 필요합니다. 그 이유는 모든 방향의 벡터 길이가 1 이어야 방향에 따른 이동 속도가 같아지기

marc-official.com

 

06 Monster Spawn 지점에서 나오기

Invoke Coroutine 사용

 

07 충돌 시 효과

728x90