Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by blackshtormx · Aug 27, 2016 at 05:09 PM · c#networkingcarvehicle

get in get out of a car. Unet

I am making multiplayer fps shooter, and it works perfectly, but when it comes to vehicles i got some problems, cause i am kinda new to Unet. I wrote script for getting in the vehicle and it works normally, for singleplayer and i have no idea how to implement this into multiplayer, i tried these "ClientRpc" stuff, (didnt work), "Command" and etc. so basically Player has Controll script (which i use for moving him) and this script has function OnControllerColliderHit, so if this happens i call void Disable(); here is script anyways: `

     void OnControllerColliderHit(ControllerColliderHit hit)
     {
         //so if we hit car
         if(hit.collider.tag == "Vehicle")
         {
             //if we pressed "E"
             if (Input.GetKeyDown(KeyCode.E))
             {
                 //call method to disable some stuff taht should be disabled, like: controller, shoot, weapons etc.
                 disable(inVehicle, hit);
             }
         }
     }
 
 
     //method to disable some stuff taht should be disabled.
     void disable(bool inVehicle, ControllerColliderHit hit)
     {
 
         //Vehicle has script PlayerControll (not for moving player, just stupid name), where it controlls how many players are in car, is there driver or not, etc.
         hit.gameObject.GetComponent<PlayerControll>().CmdSit(transform.name); //yeah, i am trying [Command] thing here.
         inVehicle = true;
 
         //character cntroller is disabled;
         cc.enabled = !inVehicle;
 
 
         //if it is not localplayer, so for other players: my colldiers should be disabled....
         if (!isLocalPlayer)
         {
             for (int i = 0; i < disableForRemote.Length; i++)
             {
                 disableForRemote[i].SetActive(!inVehicle);
             }
         }
         // as well as mine for me lol.
         else
         {
             for (int i = 0; i < disableForClient.Length; i++)
             {
                 disableForClient[i].SetActive(!inVehicle);
             }
         }
         //disabling scriptsssssss....
         for(int i = 0; i< disableComponentForClientAndRemote.Length; i++)
         {
             disableComponentForClientAndRemote[i].enabled = false;
         }
     }

(pls read them it's not big, just comments)

and My "PlayerControll script (that is NOT for controlling/moving player, just name...)"

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 public class PlayerControll : NetworkBehaviour {
 
 
     //max players in vehicle. (lol why 1?? :DDD)
     public int MaxPlayers = 1;
 
 
     //cammera
     public Camera cam;
 
     //Sync var so every player can know how many of players are in the car.
     [SyncVar]
     public int sitPlayers;
 
 
     //Sync var so every player can know does this car have driver or not(none of them is not working BTW. as well as network transform. )
     [SyncVar]
     public bool hasDriver = false;
 
 
     //this is where i "teleport" player that became driver of car. and i make player child of Driver GO.
     public GameObject Driver;
     //same here but for passanger.
     public GameObject Sitter;
 
     void Start()
     {
         cam.enabled = false;
         cam.GetComponent<AudioListener>().enabled = false;
 
         GetComponent<AudioSource>().Play();
     }
 
     void Update()
     {
         //if there is driver in car then we can controll it. (it's a paradox for me, if there is driver and i am passanger i also can controll it lol.)
         if(hasDriver)
         {
             GetComponent<carController>().enabled = true;
         }
         else
         {
             GetComponent<carController>().enabled = false;
         }
     }
 
     //command function for sitting. in car.
     [Command]
     public void CmdSit(string _player)
     {
         //i increase how many people are in car
         sitPlayers++;
 
         cam.enabled = true;
         //find player who sat there.
         GameObject player = GameObject.Find(_player);
 
 
 
         //i think you will get it >>
         if (hasDriver)
         {
             player.transform.parent = Sitter.transform;
             player.transform.position = Sitter.transform.position;
             cam.GetComponent<AudioListener>().enabled = true;
 
            
         }
         else
         {
             player.transform.parent = Driver.transform;
             hasDriver = true;
             cam.GetComponent<AudioListener>().enabled = true;
             player.transform.position = Driver.transform.position;
         }
 
 
     }
 
     //"Unet is easy" they said....
     void Out()
     {
         //havent made i yeeeet.
     }
 
 }





First of all... thanks for reading this..

and thanks for any help/ comment/downvote/upvote

--Nick.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Why does my car re-align after drift into the original direction? 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Car Audio c# script not working 3 Answers

Variables not sync'd to clients 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