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<Enemy>().dis;
Vector3 dir= Enemys.GetComponent<Enemy>().offestPosition;
Debug.Log(diss);
if(diss<20)
{
float angle =
Vector3.SignedAngle(Vector3.right, -dir, Vector3.forward);
transform.eulerAngles =
Vector3.Lerp(transform.eulerAngles, new Vector3(0, 0, angle), wavespeed);
}
if (diss < 10)
{
if (Time.time > 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;
}
}