using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
private Transform target;
public float speed = 70f;
public GameObject impactEffect;
public void Seek (Transform _target)
{
Debug.Log("seek");
target = _target;
}
void Update()
{
if (target == null)
{
Debug.Log("destroy");
// Destroy(gameObject);
return;
}
Debug.Log(target);
Vector3 dir = target.position - transform.position;
float distanceThisFrame = speed * Time.deltaTime;
if (dir.magnitude <= distanceThisFrame)
{
HitTarget();
return;
}
transform.Translate(dir.normalized * distanceThisFrame, Space.World);
transform.LookAt(target);
}
void HitTarget()
{
// GameObject effectIns = Instantiate(impactEffect, transform.position, transform.rotation);
// Destroy(effectIns, 1f);
// Debug.Log(target.gameObject);
// if (gameObject != null) {
// Destroy(target.gameObject);
// }
Destroy(gameObject);
}
}
,using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
private Transform target;
public float speed = 70f;
public GameObject impactEffect;
public void Seek (Transform _target)
{
Debug.Log("seek");
target = _target;
}
void Update()
{
if (target == null)
{
Debug.Log("destroy");
// Destroy(gameObject);
return;
}
Debug.Log(target);
Vector3 dir = target.position - transform.position;
float distanceThisFrame = speed * Time.deltaTime;
if (dir.magnitude <= distanceThisFrame)
{
HitTarget();
return;
}
transform.Translate(dir.normalized * distanceThisFrame, Space.World);
transform.LookAt(target);
}
void HitTarget()
{
// GameObject effectIns = Instantiate(impactEffect, transform.position, transform.rotation);
// Destroy(effectIns, 1f);
// Debug.Log(target.gameObject);
// if (gameObject != null) {
// Destroy(target.gameObject);
// }
Destroy(gameObject);
}
}