LookAt으로 기둥과 설치한 포구가 플레이어를 보게 함
foward는 z축 방향이었음
탄에 리지드바디를 넣었는데 중력이 적용되어서 아래로 내려갔었다 ㅋ
- Pillar
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pillar : MonoBehaviour
{
Vector3 pPiont;
Player player;
void Start()
{
player = FindObjectOfType<Player>();
}
void Update()
{
pPiont = player.transform.position;
transform.LookAt(pPiont);
}
}
- BulletGenerator
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BulletGenerator : MonoBehaviour
{
Player player;
Vector3 pPiont;
float delta = 0;
public GameObject BulletFrepabs;
void Start()
{
player = FindObjectOfType<Player>();
}
void Update()
{
delta += Time.deltaTime;
Debug.Log(delta);
if (delta > 1)
{
delta = 0;
Instantiate(BulletFrepabs, transform.position, transform.rotation);
BulletFrepabs.transform.LookAt(player.transform);
}
}
}
- Bullet
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using UnityEngine;
public class Bullet : MonoBehaviour
{
float speed = 1.1f;
Rigidbody rb;
void Update()
{
rb = GetComponent<Rigidbody>();
rb.velocity = transform.forward * speed;
}
}