Hello guys! Had a problem: got 2 classes: EnemyCreate:
using UnityEngine;
using System.Collections;
public class EnemyCreate : MonoBehaviour {
public GameObject enemyObject;
void Start () {
StartCoroutine(CreatingEnemy());
}
void Update (){
}
IEnumerator CreatingEnemy()
{
while(true)
{
CreateEnemy();
yield return new WaitForSeconds(1);
}
}
void CreateEnemy()
{
GameObject enemy = (GameObject)Instantiate(enemyObject);
enemy.transform.parent = this.gameObject.transform;
}
}
}
and Enemy:
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
Transform[] wayPoint;
float enemySpeed = 5.0f;
void Start () {
GetWay();
}
void GetWay()
{
int waysCount = GameObject.FindGameObjectWithTag ("Ways").transform.childCount;
int wayNumber = Random.Range (1, waysCount+1);
int wayPoints = GameObject.FindGameObjectWithTag ("Ways").transform.FindChild
("Way" + wayNumber).childCount;
// array of enemy way points
wayPoint = new Transform[wayPoints];
for (int i = 0; i < wayPoints; i++) {
wayPoint *= GameObject.FindGameObjectWithTag ("Ways").transform.FindChild*
-
("Way" + wayNumber).transform.FindChild ("Point" + (i + 1));*
-
}*
-
}*
-
void Update()*
-
{*
_ transform.position = Vector3.MoveTowards (transform.position, wayPoint [0].position, enemySpeed * Time.deltaTime);_
- }*
}
This doesn’t work:
transform.position = Vector3.MoveTowards (transform.position, wayPoint [0].position, enemySpeed * Time.deltaTime);
The code creates enemies with different ways to move, wayPoint[0] exist, all enemies has the same wayPoint[0] and start point(point where enemy instantiate). ATM I want to make enemy move just from start point to wayPoint[0].
Can someone help me?