Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 anarko · Nov 23, 2013 at 12:27 PM · vehicleexitcarsenter

JS Enter Exit with NetworkPlayer

Hi guys , I have test the " enter exit vehicle " on network, (JS code)
I have a probleme with the name of networkplayer. (enter vehicle its good, just for exit)
test code : "GameObject.FindWithTag("Player").active=false; " " GameObject.Find("NetworkPlayer(Clone)"+ photonView.owner).active=true; " name is "NetworkPlayer+photon.owner"

var car : Transform;
var player : Transform;
private var Player : GameObject;
var exitPoint : Transform;
var doorTriggerLeft : Transform;
private var PlayerCamera : GameObject;
var CarCamera : Camera;
var isPlayerVisible : boolean;
var Car : GameObject;
//var MainCam : GameObject;
//var WeaponCam : GameObject;
var photonView : String = "PhotonView";
var CarScript : String = "ScriptName";

function Start (){
Car.GetComponent(CarScript).enabled=false;

 Player = GameObject.FindWithTag("Player");           
 //player = Transform.FindWithTag("Player");           
  }  

function Update(){
if (Input.GetButtonUp("Use")&& isPlayerVisible){
// make player invisible and still standing
// player.gameObject.SetActiveRecursively(false);
//player.gameObject.active = false;
// GameObject.FindWithTag("Player").active=false;
GameObject.Find("NetworkPlayer(Clone)"+ photonView.owner).active=true;
// parent player to Exit Point
// player.parent = exitPoint.transform;
player.transform.localPosition = Vector3(-1.5,0,0);
// parent PlayerParent to car
exitPoint.parent = car.transform;
// exitPoint.transform.localPosition = Vector3(-0.5,0,0);
// Enable Car as controllabe object
Car.GetComponent(CarScript).enabled=true;
// MainCam.GetComponent("Camera").enabled=false;
// WeaponCam.GetComponent("Camera").enabled=false;
CarCamera.enabled = true;
}
else
{
if (Input.GetKeyUp("r")){
// make character visible again
// player.gameObject.SetActiveRecursively(true);
// player.gameObject.active = true;
GameObject.Find("NetworkPlayer(Clone)"+ photonView.owner).active=false;
// unparent player from everything
// player.transform.parent = null;
// parent Exit Point to door Trigger
// exitPoint.parent = doorTriggerLeft.transform;
// disable car as controllable
GameObject.Find("Car").GetComponent("Car").enabled=false;
// MainCam.GetComponent("Camera").enabled=true;
//WeaponCam.GetComponent("Camera").enabled=true;
CarCamera.enabled = false;

     }     
 }  

}

function OnTriggerEnter(Player : Collider) {
isPlayerVisible = true;
}

function OnTriggerExit(Player : Collider) {
isPlayerVisible = false;
}

Thanks for your help.

Comment
Add comment · 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 AlucardJay · Nov 25, 2013 at 04:21 PM 0
Share

For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

Please don't post comments as answers. Post comments by clicking the [add new comment] button, a window then open for you to type in. Answer fields are for answers only, as this is a knowledge base.

Here at Unity Answers, Answer means Solution, not Response.

  • Read this page : http://answers.unity3d.com/page/newuser.html

  • Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by anarko · Nov 25, 2013 at 04:04 PM

i have translate in CS

BUT ITS NOT GOOD JUST CAUSE " PLAYER NAME "

NullReferenceException: Object reference not set to an instance of an object Vehicl.Start () (at Assets/Car/Scripts/CSharpScripts/Vehicl.cs:31)

GameObject pl = GameObject.Find(PhotonNetwork.playerName+photonView.owner); The probleme is the player name.

Please help me .

" invokplayernetwork.cs , have source code for the palyer name. "

gameObject.name = gameObject.name + photonView.owner ;

 "Vehicl.cs"
 
 using UnityEngine;
 using System.Collections;
 
 public class Vehicl : Photon.MonoBehaviour {
 
  GameObject weaponCamera;              // drag and drop pl camera from Hierarchy to Inspector window!
 public GameObject vehicleCam;            
 Transform vehicleCameraTarget;
 GameObject vehicle; 
  GameObject pl;
 Transform GetOutPosition;                      // Empty game object, where pl will get out of the vehicle
 bool VehicleControllScript;     // Just write script name, which controls vehicle movement (controller script).  
 
 private bool  opened = false;
 private float waitTime = 1;                     // leave it as 1 
 private bool  temp = false;
 private GameObject mainCamera;
 string SoundController = "SoundController";    // Just write script name, which controls vehicle movement (controller script).  
 
     void Awake(){
         
      GameObject vehicle = GameObject.Find("Car"); ;
     GameObject pl = GameObject.Find(PhotonNetwork.playerName+photonView.owner);         
     mainCamera = GameObject.FindWithTag("MainCamera");
     weaponCamera = GameObject.FindWithTag("WeaponCamera"); 
             vehicle = GameObject.FindWithTag("Car");
         vehicleCam = GameObject.FindWithTag("CamCar");
     }
 void  Start (){
     GameObject pl = GameObject.Find(PhotonNetwork.playerName+photonView.owner);         
     mainCamera = GameObject.FindWithTag("MainCamera");
     weaponCamera = GameObject.FindWithTag("WeaponCamera"); 
             vehicle = GameObject.FindWithTag("Car"); 
         vehicleCam = GameObject.FindWithTag("CamCar");
     vehicleCam.camera.enabled = false;
     vehicle.GetComponent<Drivetrain>().enabled = false;
     vehicle.GetComponent<CarController>().enabled = false;
     vehicleCam.GetComponent<AudioListener>().enabled = false; 
             
                 vehicle.GetComponent<SoundController>().enabled = false;
 }
 
 void  Update (){
 
 
     if ((Input.GetKeyDown("e")) && opened && !temp){
         GetOut();
         opened = false;
         temp = false;
     }
 }
 
  IEnumerator Action (){
     if (!opened && !temp){
         GetIn();
         opened = true;
         temp = true;
         yield return new WaitForSeconds(waitTime);
         temp = false;
     }
 }
 
 
 void  GetIn (){
     //VehicleCamera.changeTarget = vehicleCam.transform.GetComponent<"VehicleCamera">();
     //changeTarget.target = vehicleCameraTarget;
     pl.BroadcastMessage("LightOff");
     
     // Disable all script behaviours on pl (Essentially deactivating pl control)
     Component[] coms = pl.GetComponentsInChildren<MonoBehaviour>();
     foreach(var b in coms) {
         MonoBehaviour p = b as MonoBehaviour;
         if (p)
             p.enabled = false;
     }
     
     // Disable all renderers
     Component[] gos= pl.GetComponentsInChildren<Renderer>();
     foreach( Renderer go in gos){
         go.enabled = false;
     }
     
     pl.transform.parent = vehicle.transform;
     pl.transform.position = vehicleCameraTarget.transform.position;
     pl.rigidbody.isKinematic = true;
     pl.collider.isTrigger = true;
     weaponCamera.camera.enabled = false;
     weaponCamera.GetComponent<AudioListener>().enabled = false;
     mainCamera.camera.enabled = false;
     vehicleCam.camera.enabled = true;
             vehicle.GetComponent<Drivetrain>().enabled = true;
     vehicle.GetComponent<CarController>().enabled = true;
     vehicleCam.GetComponent<AudioListener>().enabled = true;
         vehicle.GetComponent<AudioSource>().enabled = true;
         vehicle.GetComponent<AudioSource>().enabled = true; 
     vehicle.GetComponent<AudioSource>().enabled = true;     
     vehicle.GetComponent<AudioSource>().enabled = true; 
     vehicle.GetComponent<AudioSource>().enabled = true; 
     vehicle.GetComponent<AudioSource>().enabled = true; 
     vehicle.GetComponent<AudioSource>().enabled = true;     
             vehicle.GetComponent<SoundController>().enabled = true;
 }
 
 
 void  GetOut (){
     
     // Enable all script behaviours on pl (Essentially deactivating pl control)
     Component[] coms = pl.GetComponentsInChildren<MonoBehaviour>();
     foreach(var b in coms) {
         MonoBehaviour p = b as MonoBehaviour;
         if (p)
             p.enabled = true;
             
     }
     
     // Enable all renderers
         Component[] gos= pl.GetComponentsInChildren<Renderer>();
     foreach( Renderer go in gos){
         go.enabled = true;
     }
 
     pl.transform.parent = null;
     pl.rigidbody.isKinematic = false;
     pl.collider.isTrigger = false;
     pl.transform.position = GetOutPosition.transform.position;
     weaponCamera.camera.enabled = true;
     weaponCamera.GetComponent<AudioListener>().enabled = true;
     mainCamera.camera.enabled = true;
     vehicleCam.camera.enabled = false;
     vehicleCam.GetComponent<AudioListener>().enabled = false;
                 vehicle.GetComponent<AudioSource>().enabled = false; 
                 vehicle.GetComponent<AudioSource>().enabled = false; 
     vehicle.GetComponent<AudioSource>().enabled = false;     
     vehicle.GetComponent<AudioSource>().enabled = false; 
     vehicle.GetComponent<AudioSource>().enabled = false; 
     vehicle.GetComponent<AudioSource>().enabled = false; 
     vehicle.GetComponent<AudioSource>().enabled = false;     
     vehicle.GetComponent<CarController>().enabled = false;
             vehicle.GetComponent<Drivetrain>().enabled = false;
         vehicle.GetComponent<SoundController>().enabled = false;
 }
 
 }
Comment
Add comment · 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

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

17 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Enter/Exit vehicle 0 Answers

could someone help with entering/exiting a vehicle? 0 Answers

Car Enter/Exit Script Multiple Cars Problem 4 Answers

How do I make a first person player get in a vehicle? 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