일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 유니티
- 오라클
- Android
- 스크래치
- Unity
- jsp
- 아두이노
- 톰캣
- oracle
- 잡토이
- s4a
- Spring Security
- 안드로이드
- 설정
- MSSQL
- 설치
- 리브레캐드
- jobtoy
- 파주
- librecad
- 코딩
- 잡토이 메이킹 코딩 학원
- 시작하기
- mysql
- 예제
- 운정
- html5
- 라즈베리파이
- tomcat
- 강좌
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 |