Search Unity

Simplest possible car enter script

Discussion in 'Scripting' started by giraffe123, May 13, 2019.

  1. giraffe123

    giraffe123

    Joined:
    May 13, 2019
    Posts:
    1

    Here is a link to a youtube video, guy explains how he switches controller from character to car. Hey finally a video I can understand.
    I can now make a game where you enter the car, except that I feel like my brain is dead.

    The script the guy posted up for download is different than the one in the video, there is a whole bunch of stuff missing. Here is a script he got for download, and check out the one in the video. I know that even if I try to retype it and that is a S*** ton of work it will not work.

    There is also like 3 scripts attached to standard unity asset vehicle, and he is using he's own script to for the car.

    What bothers me the most is check out how simple this script should be in words:
    on press e turn off all charachter scripts, use transform to make the charachter follow the car, turn on all the car scripts, that should be disabled by default. I am very new to unity, what do I attach this script to, what variables do i declare, how do i call one script from another script. Can someone write the simplest script for standard assets.

    Goes like this
    turn off all car scripts by default
    on trigger or press e turn off all character scripts
    make the charachter fallow the car with transform
    turn on all the car scripts

    I can reverse engineer it for getting out of the car
    here are the car script names
    CarController, CarAudio. CarUserControl

    if someone is awesome enough to write this script and tell me what to attach it to please use unity standard asset names, and only make it for enter vehicle I think I can handle the exit, don't bother with coliders just make it on press e

    here is buddy's from youtube script but it needs to be as simple as possible, for and only for enter and no effin coliders, also make sure to specify what to attach it to. Someone who know what they are doing should be able to write this easily please help us noobs

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using System.Collections;
    4. using UnityStandardAssets.Vehicles.Car;
    5.  
    6. public class EnterVehicle : MonoBehaviour
    7. {
    8.     private bool inVehicle = false;
    9.     CarUserControl vehicleScript;
    10.     public GameObject guiObj;
    11.     GameObject player;
    12.  
    13.  
    14.     void Start()
    15.     {
    16.         vehicleScript = GetComponent<CarUserControl>();
    17.         player = GameObject.FindWithTag("Player");
    18.         guiObj.SetActive(false);
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void OnTriggerStay(Collider other)
    23.     {
    24.         if (other.gameObject.tag == "Player" && inVehicle == false)
    25.         {
    26.             guiObj.SetActive(true);
    27.             if (Input.GetKey(KeyCode.E))
    28.             {
    29.                 guiObj.SetActive(false);
    30.                 player.transform.parent = gameObject.transform;            
    31.                 vehicleScript.enabled = true;
    32.                 player.SetActive(false);
    33.                 inVehicle = true;
    34.             }
    35.         }
    36.     }
    37.     void OnTriggerExit(Collider other)
    38.     {
    39.         if (other.gameObject.tag == "Player")
    40.         {
    41.             guiObj.SetActive(false);
    42.         }
    43.     }
    44.     void Update()
    45.     {
    46.         if (inVehicle == true && Input.GetKey(KeyCode.F))
    47.         {
    48.             vehicleScript.enabled = false;
    49.             player.SetActive(true);
    50.             player.transform.parent = null;
    51.             inVehicle = false;
    52.         }
    53.     }
    54. }
     
  2. If you're looking for people work for you, please, try it on http://connect.unity.com/
    If you stuck with the script, show us, what you do or would you do and what are your questions?

    Basic stuff like where to put a script and why is addressed awesomely in the Learning section.
     
    SparrowGS likes this.