using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class attack1 : MonoBehaviour
{
public float wavespeed = 7;
private GameObject Enemys;
public Transform attack11;
public GameObject weapons1;
private float fireRate = 0.5f;
private float nextFire;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Enemys = GameObject.FindGameObjectWithTag("Enemy");
float diss = Enemys.GetComponent().dis;
Vector3 dir= Enemys.GetComponent().offestPosition;
Debug.Log(diss);
if(diss nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(weapons1, attack11.position, attack11.rotation);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour
{
public Transform Player;
public Vector3 offestPosition;
public float dis;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
offestPosition = Player.position - transform.position;
dis = (offestPosition).sqrMagnitude;
}
}