Hello!
I’m working on my studies and I came up with this problem I cant solve. So I have this small scene with a player tagged Astro and a car. I need to get it inside the car and switch the controls and cameras. The script is easy and should work as the Debug.Log showed it’s just fine.
But as I get near the car and try to get the script working, it just doesnt do anything. Only the Start void works when i start the game. I have seen many people doing almost the same script and It works.
Everything is assigned, console has no messages, car and player have colliders, rigidbodies and so on, separately they work just fine! The script is this one:
using UnityEngine;
public class GetInCar : MonoBehaviour
{
public GameObject car, player, dummyInCar, lights, cam;
private bool inCar = false;
WheelController driveScript;
CarCamera camScript;
private void Start() {
driveScript = GetComponent<WheelController>();
camScript = GetComponent<CarCamera>();
driveScript.enabled = false;
camScript.enabled = false;
}
public void OnTriggerStay(Collider other) {
if(other.CompareTag("Astro") && inCar == false && Input.GetKeyUp(KeyCode.E)) {
dummyInCar.SetActive(true);
player.SetActive(false);
lights.SetActive(true);
cam.SetActive(true);
driveScript.enabled = true;
camScript.enabled = true;
player.transform.parent = car.transform;
inCar = true;
}
}
private void Update() {
if(inCar == true && Input.GetKeyUp(KeyCode.E)) {
player.SetActive(true);
lights.SetActive(false);
dummyInCar.SetActive(false);
cam.SetActive(false);
player.transform.parent = null;
driveScript.enabled = false;
camScript.enabled = false;
inCar = false;
}
}
}