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 PattyGames · Jul 08, 2013 at 04:57 PM · carenter

Problem with my car enter/exit script

Hi, everyone! I'm pretty new to Unity Answers as a user, but I've been working with Unity pro for over 2 years. I am working on a 3rd person action shooter with freeroaming as one of the main features, but I'm struggeling to get one of my scripts working properly. I have a scene where my player (in the storyline a gangster) needs to enter a car, so I have a car object with a 'carcontrol' script attached to it. I put a cube as a child next to the cardoor, disabled the renderer and made it a trigger. I've got a player object, and I have two camera's. One for the car, and one for the player. I've written this script, and attached it to the trigger next to the cardoor:

 var isVisable : boolean;
 var gangster : GameObject;
 var car : GameObject;
 var carcam : Camera;
 var gangstercam : Camera;
 var isinCar : boolean;
 
 function Start(){
 isVisable = true;
 isinCar = false;
 gangster.active = true;
 car.GetComponent(CarControl).enabled = false;
 carcam.active = false;
 gangstercam.active = true;
 }
 
 function Update(){
 if(Input.GetButtonUp("Getincar") && !isVisable == true){
 isinCar = true;
 gangster.active = false;
 car.GetComponent(CarControl).enabled = true;
 carcam.active = true;
 gangstercam.active = false;
 }else{
 isinCar = false;
 gangster.active = true;
 car.GetComponent(CarControl).enabled = false;
 carcam.active = false;
 gangstercam.active = true;
 }
 
 if(Input.GetButtonUp("Getincar") && !isinCar == true){
 isinCar = false;
 gangster.active = true;
 car.GetComponent(CarControl).enabled = false;
 carcam.active = false;
 gangstercam.active = true;
 }
 }
 
 function OnTriggerEnter(other : Collider){
 if(other.gameObject.name == "PLAYER"){
 isVisable = true;
 }
 }
 
 function OnTriggerExit(other : Collider){
 if(other.gameObject.name == "PLAYER"){
 isVisable = false;
 }
 }

I've put the script on the trigger next to the cardoor. Everything in the script looked fine, and the console gave no errors at all. When I tested the level, and went into the trigger with my player, I pushed the "Getincar" button. My player deactivated, the carcontrol script turned on and the cameras switched like they should, but then immediatly turned back to their original state. No matter how much I push the button, they just keep on turning back within half a-second or something. Could anyone please point out what I am doing wrong here? Thanks in advance!

-Patrick Schut (PattyGames)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Ian094 · Aug 03, 2013 at 01:02 AM

Hey, This script should help you out:

 var car : Transform;
 var gangster : Transform;
 var exitPoint : Transform;
 var doorTriggerLeft : Transform;
 var gangsterCam : Camera;
 var CarCam : Camera;
 
 function Start(){
 
 }
 
 function Update(){
 if(Input.GetButton("GetinCar")){
 GetComponent(CarControl).enabled = true;
 gangster.gameObject.SetActiveRecursively(false);
 gangster.gameObject.active = false;
 CarCam.enabled = true;
 gangstercam.enabled = false;
 gangster.parent = exitPoint.transform;
 exitPoint.transform.localPosition = Vector3(-0.5,0,0);
 exitPoint.parent = car.transform;
 exitPoint.transform.localPosition = Vector3(-0.5,0,0);
 }
 else{
 if(Input.GetButton("GetinCar")){
 GetComponent(CarControl).enabled = false;
 gangster.gameObject.SetActiveRecursively(true);
 gangster.gameObject.active = true;
 CarCam.enabled = false;
 gangstercam.enabled = true;
 gangster.transform.parent = null;
 exitPoint.parent = doorTriggerLeft.transform;
 }
 }
 }
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

17 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Gui placement help 1 Answer

Yield function goes slow sometimes/differently? 2 Answers

OnCollisionEnter called twice 2 Answers

How can i fix this error? 2 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