일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- tomcat
- Unity
- 운정
- 예제
- 아두이노
- 스크래치
- Android
- html5
- 오라클
- 파주
- Spring Security
- 유니티
- 리브레캐드
- 잡토이 메이킹 코딩 학원
- librecad
- 코딩
- s4a
- 설정
- 설치
- MSSQL
- jobtoy
- jsp
- 라즈베리파이
- oracle
- 시작하기
- 안드로이드
- 강좌
- mysql
- 톰캣
- 잡토이
Archives
- Today
- Total
랩제이
[유니티 2D] 플레이어 따라오기 본문
게임오브젝트가 플레이어를 따라오도록 합니다.
* Rotate.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
public GameObject target;
private void
OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag == "Bullet")
{
transform.position =
new Vector3(
transform.position.x + 1,
0,
0
);
}
}
void Start()
{
}
void Update()
{
Vector3 dir = target.transform.position - transform.position;
float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
Quaternion r = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = r;
transform.position = Vector3.MoveTowards(
transform.position,
target.transform.position,
0.01f
);
}
}
'유니티' 카테고리의 다른 글
[유니티 2D] 기어 회전하기 (0) | 2024.03.10 |
---|---|
[유니티 2D] 게임 오브젝트와 게임 오브젝트 사이의 거리 (0) | 2024.03.10 |
[유니티 2D] 미로 - 생명 (0) | 2024.03.10 |
[유니티 2D] 미로 - Bullet(총알) 만들기 (0) | 2024.03.10 |
[유니티 2D] 미로 - 유령이 플레이어 바라보고 쫓아오기 (0) | 2024.03.10 |