Enter/Exit Vehicle With UNet
All the topic's I've viewed so far are not what I want. I currently have a good, dependable script for entering and exiting a vehicle in singleplayer, but I'm at a total loss trying to network it.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.Vehicles.Car;
using UnityStandardAssets.Characters.FirstPerson;
public class GameManager : MonoBehaviour {
public Camera playerCam;
public FirstPersonController FPSCon;
public GameObject Player;
public GameObject m_Car;
public Transform carParent;
bool guiEnable = false;
public Camera cam;
void Start () {
cam.enabled = false;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)) {
if (cam.enabled == true) {
cam.enabled = false;
FPSCon.enabled = true;
Player.GetComponent<CharacterController> ().enabled = true;
playerCam.enabled = true;
Player.transform.parent = null;
m_Car.gameObject.GetComponent <CarUserControl> ().enabled = false;
}
}
}
void OnTriggerStay (Collider col) {
if (col.name == "FPSController") {
guiEnable = true;
if (Input.GetKey (KeyCode.E)) {
if (cam.enabled == false) {
cam.enabled = true;
FPSCon.enabled = false;
Player.GetComponent<CharacterController> ().enabled = false;
playerCam.enabled = false;
guiEnable = false;
Player.transform.SetParent (carParent);
m_Car.gameObject.GetComponent <CarUserControl> ().enabled = true;
}
}
}
}
void OnTriggerExit (Collider col) {
if (col.name == "FPSController") {
guiEnable = false;
}
}
void OnGUI () {
if (guiEnable != false) {
GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 100, 50), "E to Enter.");
} else {
GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 50, 50), " ");
}
}
}
If anyone can help me out, I would be forever in your debt. Thanks in advance.
same problem, at least in my case when player gets in car his position is same as cars :ddd ps(car starts flying etc, so dont ask me how i did it :) )
Answer by dooly123 · Jun 09, 2016 at 10:13 AM
here you go have not test it myself :) probly still only 50% complete or so. havent set up a way to stop it from telling it not to get in if other other ect.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
using UnityStandardAssets.Vehicles.Car;
using UnityStandardAssets.Characters.FirstPerson;
public class DevCode : NetworkBehaviour {
public Camera playerCam;
public FirstPersonController FPSCon;
public GameObject Player;
public GameObject m_Car;
public Transform carParent;
bool guiEnable = false;
public Camera cam;
void Start () {
cam.enabled = false;
}
void Update () {
if (!isLocalPlayer)
{
return;
}
if (Input.GetKeyDown (KeyCode.Escape)) {
if (cam.enabled == true) {
cam.enabled = false;
FPSCon.enabled = true;
Player.GetComponent<> ().enabled = true;
playerCam.enabled = true;
Player.transform.parent = null;
m_Car.gameObject.GetComponent <CarUserControl> ().enabled = false;
}
}
}
void OnTriggerStay (Collider col) {
if (col.name == "FPSController") {
guiEnable = true;
if (Input.GetKey (KeyCode.E)) {
if (cam.enabled == false) {
cam.enabled = true;
FPSCon.enabled = false;
Player.GetComponent<CharacterController> ().enabled = false;
playerCam.enabled = false;
guiEnable = false;
Player.transform.SetParent (carParent);
m_Car.gameObject.GetComponent <CarUserControl> ().enabled = true;
}
}
}
}
void OnTriggerExit (Collider col) {
if (col.name == "FPSController") {
guiEnable = false;
}
}
void OnGUI () {
if (guiEnable != false) {
GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 100, 50), "E to Enter.");
} else {
GUI.Label (new Rect (Screen.width / 2, Screen.height / 2, 50, 50), " ");
}
}
}
I have no idea why that should work. where are commands, rpc's etc.
correct this script is not complete i have made a working version but i will not be releasing it as its going to come out on the asset store.
sorry if you realy need a script that does this just give me messages.
yes i need it, but i think as most of the people here, we need explanation or even a hint so we can do it ourselves.
Yeah, this doesn't work in multiplayer. It won't tell anyone else what you are doing.
Your answer