/// <summary> /// We use this callback to instantiate player vehicle for the game scene. /// This instantiated object is then positionned on the track scene /// </summary> /// <param name="conn">Conn.</param> /// <param name="playerControllerId">Player controller identifier.</param> public override GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId) { GameObject vehicle = null; // we look for a reference to generic interface of the racing manager class RaceManager manager = FindObjectOfType <RaceManager>(); // we get the associated lobby player object GameObject newPlayer = conn.playerControllers[playerControllerId].gameObject; OnlineLobbyPlayer lobbyplayer = newPlayer.GetComponent <OnlineLobbyPlayer>(); // we determine the start position Vector3 startPosition = manager.StartPositions[_currentStartPosition]; Quaternion startRotation = Quaternion.Euler(new Vector3(0, manager.StartAngleDegree, 0)); // we increment start position for next player _currentStartPosition++; // we instantiate the player vehicle vehicle = (GameObject)Object.Instantiate( AvailableVehiclesPrefab[lobbyplayer.VehicleSelectedIndex], startPosition, startRotation ); return(vehicle); }
/// <summary> /// Initializes various references /// </summary> protected virtual void Awake() { // Init managers _collider = GetComponent <Collider>(); _raceManager = FindObjectOfType <RaceManager>(); _rigidbody = GetComponent <Rigidbody>(); IsOnSpeedBoost = false; }
/// <summary> /// Initialization /// </summary> public virtual void Start() { _controller = GetComponent <BaseController>(); _raceManager = FindObjectOfType <RaceManager>(); // we get the list of AI waypoint if (_raceManager.AIWaypoints != null) { _AIWaypoints = _raceManager.AIWaypoints.GetComponent <Waypoints>().items; // the AI will look for the first waypoint in the list _currentWaypoint = 0; _targetWaypoint = _AIWaypoints[_currentWaypoint]; } }
/// <summary> /// Draws repositionable handles at every point in the path, for easier setup /// </summary> public void OnSceneGUI() { Handles.color = Color.green; RaceManager t = (target as RaceManager); if (t.Checkpoints != null) { for (int i = 0; i < t.Checkpoints.Length; i++) { if (t.Checkpoints[i] != null) { // draws the path item number GUIStyle style = new GUIStyle(); style.normal.textColor = Color.red; Handles.Label(t.Checkpoints[i].transform.position + (Vector3.down * 0.4f) + (Vector3.right * 0.4f), "CP-" + i, style); } } } for (int i = 0; i < t.StartPositions.Length; i++) { Vector3 oldPoint = t.StartPositions[i]; Handles.color = Color.magenta; // we draw the start angle Handles.ConeCap(0, oldPoint, Quaternion.AngleAxis(t.StartAngleDegree, Vector3.up), 2f); Handles.color = Color.green; EditorGUI.BeginChangeCheck(); // we draw the path item number GUIStyle style = new GUIStyle(); style.normal.textColor = Color.gray; Handles.Label(t.StartPositions[i] + (Vector3.down * 0.4f) + (Vector3.right * 0.4f), "start-" + (i + 1), style); // we draw a movable handle Vector3 newPoint = Handles.PositionHandle(oldPoint, Quaternion.identity); // records changes if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Start Position Move Handle"); t.StartPositions[i] = newPoint; } } }