Search Unity

In and Out of Vehicle Camera's (Partially Solved)

Discussion in 'Scripting' started by Vampyr_Engel, Nov 29, 2018.

  1. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    I have a problem and the problem is that I don't know how to disable the players camera when getting into the players vehicle I got the script of YouTube and it actually works Its just that the cameras are totally disabled when you get into the vehicle and also the vehicle doesn't stay still often enough for the player to get in I would also like to know how to do flight as well so I can have it from simple joysticks to full H.O.T.A.S systems. Iwant to be able to disable both 1st and 3rd person camera's when I am in the vehicle and have the 1st and 4rd person cameras in the vehicle work and then when the player ger gets out diable the 1st and 3rd person camera's of the vehicle as well as disable the vehicle properly

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. //using UnityStandardAssets.Vehicles.Car;
    4.  
    5. public class EnterVehicle : MonoBehaviour
    6. {
    7.     // CarUserControl vehicleScript;
    8.     private bool inVehicle = false;
    9.     public HoverTank vehicleScript;
    10.     public GameObject guiObj;
    11.     public GameObject Player;
    12.  
    13.     //public GameObject playerbackup;
    14.  
    15.  
    16.     void Start()
    17.     {
    18.        // vehicleScript = GetComponent<CarUserControl>();
    19.         vehicleScript = GetComponent <HoverTank>();
    20.         Player = GameObject.FindWithTag("Player");
    21.         guiObj.SetActive(false);
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void OnTriggerStay(Collider other)
    26.     {
    27.         if (other.gameObject.tag == "Player" && inVehicle == false)
    28.         {
    29.             guiObj.SetActive(true);
    30.             if (Input.GetKey(KeyCode.E))
    31.             {
    32.                 guiObj.SetActive(false);
    33.                 Player.transform.parent = gameObject.transform;
    34.  
    35.                 vehicleScript.enabled = true;
    36.                 Player.SetActive(false);
    37.                 inVehicle = true;
    38.             }
    39.         }
    40.     }
    41.     void OnTriggerExit(Collider other)
    42.     {
    43.         if (other.gameObject.tag == "Player")
    44.         {
    45.             guiObj.SetActive(false);
    46.         }
    47.     }
    48.     void Update()
    49.     {
    50.         if (inVehicle == true && Input.GetKey(KeyCode.F))
    51.         {
    52.             vehicleScript.enabled = false;
    53.             Player.SetActive(true);
    54.             Player.transform.parent = null;
    55.             inVehicle = false;
    56.         }
    57.     }
    58. }
     
  2. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    What it looks like

     
  3. Vampyr_Engel

    Vampyr_Engel

    Joined:
    Dec 17, 2014
    Posts:
    449
    Managed to get 1st person camera to work Modified the script a bit but now it cuts out my other camera's same when I go 3rd person and somehow I have lost mouselook and the damn hovertank doesn't stay still for the player to exit and enter the vehicle properly

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. //using UnityStandardAssets.Vehicles.Car;
    4.  
    5. public class EnterVehicle : MonoBehaviour
    6. {
    7.     // CarUserControl vehicleScript;
    8.     private bool inVehicle = false;
    9.     public HoverTank vehicleScript;
    10.     public GameObject guiObj;
    11.     public GameObject Player;
    12.     public Camera hoverCam;
    13.     private bool inVeh;
    14.  
    15.     //public GameObject playerbackup;
    16.  
    17.  
    18.     void Start()
    19.     {
    20.        // vehicleScript = GetComponent<CarUserControl>();
    21.         hoverCam.enabled = false;
    22.         //hoverCam2.enabled = false;
    23.         inVeh = false;
    24.         vehicleScript = GetComponent <HoverTank>();
    25.         Player = GameObject.FindWithTag("Player");
    26.         guiObj.SetActive(false);
    27.     }
    28.  
    29.     // Update is called once per frame
    30.     void OnTriggerStay(Collider other)
    31.     {
    32.         if (other.gameObject.tag == "Player" && inVehicle == false)
    33.         {
    34.             guiObj.SetActive(true);
    35.             if (Input.GetKey(KeyCode.E))
    36.             {
    37.                 guiObj.SetActive(false);
    38.                 Player.transform.parent = gameObject.transform;
    39.                 hoverCam.enabled = true;
    40.                 //hoverCam2.enabled = true;
    41.                 inVeh = true;
    42.                 vehicleScript.enabled = true;
    43.                 Player.SetActive(false);
    44.                 inVehicle = true;
    45.             }
    46.         }
    47.     }
    48.     void OnTriggerExit(Collider other)
    49.     {
    50.         if (other.gameObject.tag == "Player")
    51.         {
    52.             guiObj.SetActive(false);
    53.         }
    54.     }
    55.     void Update()
    56.     {
    57.         if (inVehicle == true && Input.GetKey(KeyCode.F))
    58.         {
    59.             vehicleScript.enabled = false;
    60.             hoverCam.enabled = false;
    61.             //hoverCam2.enabled = false;
    62.             inVeh = false;
    63.             Player.SetActive(true);
    64.             Player.transform.parent = null;
    65.             inVehicle = false;
    66.         }
    67.     }
    68. }