예제 #1
0
    private GameObject InitPlayer(GameObject track)
    {
        Debug.Log($"Prefabs/Player/Player");
        GameObject playerPrefab = Resources.Load <GameObject>($"Prefabs/Player/Player");
        GameObject player       = Instantiate(playerPrefab);

        player.name             = "Player";
        player.transform.parent = transform;

        player.transform.position = track.transform.Find("spawn_point").position;

        Transform pointsContainer = track.transform.Find("points");

        Transform[] points = new Transform[pointsContainer.childCount];

        for (int i = 0; i < pointsContainer.childCount; i++)
        {
            Debug.Log(pointsContainer.GetChild(i).name);
            Transform point = pointsContainer.Find("point_" + i);
            points[i] = point;
        }

        MoveComponent moveComponent = player.GetComponent <MoveComponent>();

        moveComponent.InitPoints(points);
        moveComponent.AddEventListener();

        return(player);
    }