Answer the question
In order to leave comments, you need to log in
How to set movement coordinates for a unit?
I need to put the unit at certain coordinates and pass it the value of where to go
public class Unit : MonoBehaviour{ // прикреплен к префабу
public Vector3 EndPoint;
private float speed = 2f;
void Start(){
//EndPoint= new Vector3(15, 0, 15);
}
void Update(){
transform.position = Vector3.MoveTowards(transform.position, EndPoint, speed*Time.deltaTime);
}
}
public class Spawn : MonoBehaviour{
void Start(){
SpawnUnit();
}
void SpawnUnit(){
Unit Prefab = Resources.Load("Units/unit1", typeof(Unit)) as Unit;
Instantiate(Prefab, new Vector3(5, 0, 5), Quaternion.identity);
Prefab.EndPoint = new Vector3(15, 0, 15);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question