Backend/unity

[유니티] 오브젝트 제자리 회전

민57 2020. 4. 19. 16:07
실행화면

https://youtu.be/RtDHDtRwa94

 

 

 

회전하기

 

서양 배가 모델입니다. 카메라 앞에 잘 서있어요

아이템이 제자리에서 빙글빙글 돌아가도록 스크립트를 작성해보겠습니다. 

 

Item.cs

public class Item : MonoBehaviour
{
    float rotSpeed = 100f;

    void Update()
    {
        transform.Rotate(new Vector3(0, rotSpeed * Time.deltaTime, 0));
    }

    private void OnTriggerEnter(Collider other)
    {
        if(other.tag == "Player")
        {
            Debug.Log("- 아이템 획득");
            Destroy(gameObject);
        }
    }
}

 

Update()에서 이 스크립트를 가지고 있는 객체의 Rotation의 Y값을 계속해서 변경시켜줍니다.

OnTriggerEnter : 닿은 오브젝트의 태그가 "Player"일 때 로그를 띄우고 해당 객체를 제거합니다.

728x90