Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mnm53 · Nov 30, 2014 at 08:43 PM · multiplevehicleexitenter

Car Enter/Exit Script Multiple Cars Problem

Hello, im quite new to unity answers and i was just hoping that someone could help me with my problem, ive been racking my brain for ages and i just cant figure it out

basicly my enter exit script works 100% fine whenever i have one single car in my scene but once i add a second (by copy and pasting the first) the second car wont disable the player but the player will still be attached to the car and the car will be controllable however the other car will always work perfectly fine. another thing i noticed is that while driving the second car i cant diable the player through the inspectors check box as it immediately becomes rechecked instantly

here is my enter/exit script (its in js):

 var inTrigger = false;
 var incar = false;
 var player : Transform;
 var exitPoint : Transform;
 var Car : Transform;
 function OnTriggerEnter(collider : Collider)
  {
      if(collider.tag == "Player")
      {
          inTrigger = true;
       }}
       
 function OnTriggerExit(collider : Collider)
  {
      if(collider.tag == "Player")
      {
          inTrigger = false;
       }}
       
       
 function Update(){
 
 if(inTrigger){
     if (Input.GetKeyDown ("e"))
         incar = (!incar);
     }
 if(inTrigger == false){
 incar = false;
 }
 
 if(incar){
 
          player.gameObject.SetActive (false);
          // Parent player to ExitPoint
          player.parent = exitPoint.transform;
          player.transform.localPosition = Vector3(-0.25,0,0);
          //Parent playerParent to car
          exitPoint.parent = Car.transform;
          exitPoint.transform.localPosition = Vector3(-0.25,0,0);
          // Enable car as controllable object
          Car.GetComponent("DrivingScript").enabled = true;
 
 }
 else{
 
 
          player.gameObject.SetActive (true);
          // Unparent Player from everything.
          player.transform.parent = null;
          // Disable car as a controllable
          Car.GetComponent("DrivingScript").enabled = false;
 }
 
 }


Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mnm53 · Dec 04, 2014 at 02:44 AM 0
Share

Anyone please? I have no clue what to do. Even if your not completely sure about it just somebody to help elibrate with would be amazing

avatar image M-G-Production · Dec 04, 2014 at 04:07 AM 0
Share

Did you know about OnTriggerStay() fonction? You should give it a try! I think there is conflict your some vars.

OnTriggerStay is executed every frame the player is in the collider. So you could change OnTriggerEnter function for OnTriggerStay() and You could put your input.getkey in this function and probably get rid of the inTrigger bool...

I'll look further...

avatar image mnm53 · Dec 04, 2014 at 10:16 PM 0
Share

thank you soo much for commenting you have no idea how much this means to me. i really apreciate your help, and thanks for the tip with OnTriggerStay()

avatar image mnm53 · Dec 06, 2014 at 10:19 PM 0
Share

Does anyone else have a clue as to what is wrong?

avatar image Hybridizer · Feb 09, 2016 at 09:32 AM 0
Share

@mnm53 Could I get a little more information about this script? I'm very interested in it, but I don't know too much about scripting, so I'm not sure how to make it work in my scene. A few questions:

What script language is it written in?

What game object(s) do I add the script to (is it just a universal script to be added to a single empty object, or to be added to every vehicle, etc)?

Is that the full script, or is it missing the opening lines (such as "using UnityEngine;" etc)?

Is the script compatible with Unity 5, or does it need to be updated?

Does the name of the script matter, or can I name it anything without encountering a compiling error?

The reference to another script, "DrivingScript", is that just a placeholder name that can be replaced with any script that controls the vehicle in question, such as the Standard Assets' "Car Controller" script?

Sorry for all the questions, but when it comes to scripting, I need all the help I can get. Thanks.

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Wiki

Answer by mnm53 · Dec 10, 2014 at 09:12 AM

i actually managed to figure it out and it really still confuses me but i decided to test someone else's Enter/Exit Script and i found the problem to be with this line: incar = (!incar);

and the problem stops if you include a else function like i have done in the completed fully functional script below (btw the script below is actually another script ive found on unity answers and ive modified it if a few ways, it still follows roughly the same principle though)

  var car : Transform;
  var player : Transform;
  var exitPoint : Transform; 
  var doorTriggerLeft : Transform;
  var PlayerCamera : Camera;
  var CarCamera : Camera; 
  var isPlayerVisible : boolean;
  var driving : boolean;
  function Update()
  {
  if(driving){
  isPlayerVisible = true;
  }
  if (Input.GetKeyDown("f")&& isPlayerVisible) 
  {
  driving = !driving;
 if(driving){
 
  player.gameObject.active = false;
 
  player.parent = exitPoint.transform;
  player.transform.localPosition = Vector3(0,0,0);
 
  exitPoint.parent = car.transform;
  exitPoint.transform.localPosition = Vector3(-0.5,0,0); 
 
  car.GetComponent("DrivingScript").enabled=true;
  PlayerCamera.enabled = false; 
  CarCamera.enabled = true;
  }
  else
  {
  
  player.gameObject.active = true;
 
  player.transform.parent = null;
 
 
  exitPoint.parent = car.transform;
 
  car.GetComponent("DrivingScript").enabled=false;
  PlayerCamera.enabled = true; 
  CarCamera.enabled = false; 
  }
  }
  }
  
  function OnTriggerEnter(Player : Collider)
  {
  isPlayerVisible = true;
  }
  
  function OnTriggerExit(Player : Collider)
  {
  isPlayerVisible = false;
  }
  
  



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Delta6 · May 21, 2015 at 09:16 AM

yah I have also been looking for a script that will work in ta tank and a helicopter and have found little hope. but this script seems very promising.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by dooly123 · Oct 17, 2016 at 07:25 AM

hay all been working on a script for a few months now its finished sadly its not free but if you are not able to get ur own one to work i thought it might help you get back on track :) https://forum.unity3d.com/threads/enter-exit-vehicle-networked-photon-cars-planes-offline-online-easy-to-use.436698/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enter/Exit vehicle 0 Answers

Problem Enter and Exit with Vehicle 2 Answers

How do you make character enter and exit vehicles. 1 Answer

Enter\Exit Car With Doors. 0 Answers

could someone help with entering/exiting a vehicle? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges