Any feed back is welcome I trying to get enemies I added to game to move toward the playership as if to attach and follow once I can get this done with the movement I will get them to shoot at the playership. right now all the new enemies I added are spinning really fast in circles.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasicEnemy : MonoBehaviour
{
public Transform target;
public float speed = 3f;
public float attack1Range = 1f;
public int attack1Damage = 1;
public float timeBetweenAttacks;
// Use this for initialization
void Start()
{
Rest();
}
// Update is called once per frame
void Update()
{
}
public void MoveToPlayer()
{
//rotate to look at player
transform.LookAt(target.position);
transform.Rotate(new Vector3(0, -90, 0), Space.Self);
//move towards player
if (Vector3.Distance(transform.position, target.position) > attack1Range)
{
transform.Translate(new Vector3(speed * Time.deltaTime, 0, 0));
}
}
public void Rest()
{
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyTerritory : MonoBehaviour
{
public BoxCollider territory;
GameObject player;
bool playerInTerritory;
public GameObject enemy;
BasicEnemy basicenemy;
// Use this for initialization
void Start()
{
player = GameObject.FindGameObjectWithTag("Player");
basicenemy = enemy.GetComponent<BasicEnemy>();
playerInTerritory = false;
}
// Update is called once per frame
void Update()
{
if (playerInTerritory = true)
{
basicenemy.MoveToPlayer();
}
if (playerInTerritory = false)
{
basicenemy.Rest();
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject == player)
{
playerInTerritory = true;
}
}
void OnTriggerExit(Collider other)
{
if (other.gameObject == player)
{
playerInTerritory = false;
}
}
}