I have a script for enemy and i and like to make a list of points, where enemy can go.
i tryed make it with serialize field construct, but clones(prefabs) spawn without a transform positions
public class Enemy : MonoBehaviour
{
private Transform endPoint;
public int health;
public float speed;
private float progress;
private void Start()
{
endPoint = GameObject.FindGameObjectWithTag("EndPos").GetComponent<Transform>();
}
private void Update()
{
if (health <= 0)
{
Destroy(gameObject);
}
}
public void TakeDamage(int damage)
{
health -= damage;
}
private void FixedUpdate()
{
transform.position = Vector2.MoveTowards(transform.position, endPoint.position, progress * Time.deltaTime);
progress = speed;
}
}
New contributor
Влад Болталин is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.