Answer the question
In order to leave comments, you need to log in
How to solve the problem with the login script?
I made a script so that the player could get into the car, but after pressing the "F" key, none of the car control scripts turned on and the player control scripts did not turn off, the same situation with the camera of the car and the player. Here is the script itself:
public class CarDoorScript : MonoBehaviour
{
public GameObject player;
public Camera playerCamera;
public Camera carCamera;
public GameObject car;
public Transform DriverPoint;//позиция игрока при входе в машину
public Transform ExitPoint;// позиция игрока при выходе из машины
[SerializeField]
private bool inCar = false;
private void OnTriggerStay(Collider other)
{
if (other.GetComponent<PlayerCharacter>() && Input.GetKey(KeyCode.F) && !inCar
&& car.GetComponent<WheelScript>().enabled == !true && player.GetComponent<CharacterMove>().enabled == true)
{
playerCamera.enabled = false;
carCamera.enabled = true;
player.transform.position = DriverPoint.transform.position;
car.GetComponent<WheelScript>().enabled = true;
player.GetComponent<CharacterMove>().enabled = false;
inCar = true;
}
if (Input.GetKey(KeyCode.F) && inCar
&& car.GetComponent<WheelScript>().enabled == true && player.GetComponent<CharacterMove>().enabled == false)
{
playerCamera.enabled = true;
carCamera.enabled = false;
player.transform.position = ExitPoint.transform.position;
car.GetComponent<WheelScript>().enabled = false;
player.GetComponent<CharacterMove>().enabled = true;
inCar = false;
}
}
}
Answer the question
In order to leave comments, you need to log in
Have you tried connecting with a debugger? I took a quick look, but everything looks so that after the first condition is triggered, the second one will immediately work. Do at least else if
, but it's better, of course, to make a special component for the button and separate the logic for entering / exiting the car. Similar to UI.Button .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question