- Home /
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.
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.
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;
}
}
Your answer
Follow this Question
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