- Home /
Entering and exiting vehicles in Photon Cloud
Hi, basically i want to be able to enter/ exit my jet i made in photon cloud, currently you can but only on player can be in the vehicle.
Here is the current code:
using UnityEngine;
using System.Collections;
public class Jet_Entre : MonoBehaviour {
public GameObject Player;
public Jet_Network Jetwork;
public Jet jet;
public Jet_Cam Cam;
public bool CanEnter = false;
void Start(){
}
void OnTriggerEnter(Collider other){
if(other.gameObject.tag == "Player"){
Player = other.gameObject;
CanEnter = true;
}
}
// Use this for initialization
void OnTriggerExit(Collider other){
Player = null;
CanEnter = false;
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.F)&& CanEnter == true){
Jetwork.enabled = true;
Player.SetActiveRecursively(false);
Player.transform.parent = gameObject.transform;
// jet.enabled = true;
Cam.enabled = true;
}
if(Input.GetKeyDown(KeyCode.R)){
Player.transform.localPosition = new Vector3(0,3,0);
jet.enabled = false;
Cam.enabled = false;
Jetwork.enabled = false;
Player.SetActiveRecursively(true);
Player.transform.parent = null;
Player.transform.rotation = new Quaternion(0,90,0,0);
}
}
}
Can someone help me make it so more than one person can be in the jets. Thanks :)
its a shame this is a 2 year old thread :/ I'm having so many issues with my vehicles its not fair lol. Just not sure how I should structure my vehicle code... Can't seem to find anyone to help me either.!
Answer by garner · Apr 02, 2012 at 01:35 PM
You need a variable to store player1 and player 2 otherwise the references are reassigned. You can create an array of players too.
public GameObject Player1;
public GameObject Player2;
public bool Player1CanEnter = false;
public bool Player2CanEnter = false;
if(other.gameObject.tag == "Player1"){
Player1 = other.gameObject;
Player1CanEnter = true;
}
else if (othere.gameObject.tag == "Player2"){
Player2 = other.gameObject;
Player2CanEnter = true;
}
cool, i think ill go with the array as there will be up to 12 players in the server.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065809im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Enter/exit buildings spawn 2 Answers
how do I enter vehicles 1 Answer
OnTriggerStay/Enter/Exit for a second time? 1 Answer
Enter\Exit Car With Doors. 0 Answers