• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by SonicScrew12 · Feb 16, 2016 at 01:07 PM · networkingvehicles

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 ve$$anonymous$$cle in singleplayer, but I'm at a total loss trying to network it.

 using UnityEngine;
 using System.Collections;
 using UnityStandardAssets.Ve$$anonymous$$cles.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.

Comment
blackshtormx

People who like this

1 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image blackshtormx · Aug 27, 2016 at 09:03 AM 0
Share

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 :) )

1 Reply

· Add your reply
  • Sort: 
avatar image

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.Ve$$anonymous$$cles.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), " ");
             }
         }
     }
 


Comment

People who like this

0 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image blackshtormx · Aug 27, 2016 at 09:02 AM 0
Share

I have no idea why that should work. where are commands, rpc's etc.

avatar image dooly123 · Aug 29, 2016 at 12:28 AM 0
Share

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.

avatar image blackshtormx dooly123 · Sep 13, 2016 at 04:36 PM 0
Share

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.

avatar image Semni · Mar 14, 2017 at 09:37 PM 0
Share

Yeah, this doesn't work in multiplayer. It won't tell anyone else what you are doing.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Networked vehicle physics - to rigidbody or not rigidbody? 0 Answers

Trying to add drive-able vehicles to my multiplayer FPS 1 Answer

Unity Networking Cannot Join Match - Room Disappears 1 Answer

Fail to Connect to NetworkServer 1 Answer

Unet not connecting over the internet 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges