public void createWorker() { GameObject activeObj = manager.getActiveObject(); IcanHaveRoad haveRoad = activeObj.GetComponent(typeof(IcanHaveRoad)) as IcanHaveRoad; RoadScript roadScript = haveRoad.getRoad(); GameObject newWorker = Instantiate(Worker, roadScript.getTopObject().transform.position, Quaternion.identity); WorkerScript worker = newWorker.GetComponent(typeof(WorkerScript)) as WorkerScript; worker.setDirection(roadScript.getBottomObject().transform.position); worker.setRoadMovingOn(roadScript); }
// Update is called once per frame void Update() { if (moveDirection != transform.position) { move(); } else { if (transform.position == roadMovingOn.getBottomObject().transform.position) { IcanHaveRoad haveRoad = roadMovingOn.getBottomObject().GetComponent(typeof(IcanHaveRoad)) as IcanHaveRoad; RoadScript newRoad = haveRoad.getRoad(); roadMovingOn = newRoad; if (moveDirection != newRoad.getTopObject().transform.position) { moveDirection = newRoad.getTopObject().transform.position; } else { moveDirection = haveRoad.getRoad().getBottomObject().transform.position; } } else { IcanHaveRoad haveRoad = roadMovingOn.getTopObject().GetComponent(typeof(IcanHaveRoad)) as IcanHaveRoad; RoadScript newRoad = haveRoad.getRoad(); roadMovingOn = newRoad; if (moveDirection != newRoad.getBottomObject().transform.position) { moveDirection = newRoad.getBottomObject().transform.position; } else { moveDirection = newRoad.getTopObject().transform.position; } } } }