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 DasFloX · Aug 08, 2012 at 10:21 AM · cardisablechildrenmount

How do I mount a Vehicle?

My Problem is, I'm trying to mount a vehicle by deactivating the Player and his camera (which is a child of the player) and activating the car's Drive Script and it's camera using a "MountVehicle" Script on the Car. If I want to Exit the car, I dectivate the Drive Script and the Camera, activate the Player and pull the Player to the ExitPoint (a child of the Car).

The Code looks like this:

 var Cam : GameObject;
 
 var Player : GameObject;
 
 var driving : boolean = false;
 
 var DriveScript : Component;
 
 var ExitPoint : Transform;
 
 
 function Start () {
 
 }
 
 function Update () {
 
  if(driving==true && Input.GetButtonDown("E")){
  Cam.active = false;
  DriveScript.active = false;
  Player.transform.position = ExitPoint.position;
  Player.active = true;
  
  driving = false;
  }
 
 }
 
 function OnTriggerStay () {
 
  if(Input.GetButtonDown("E")){
  
  //activate Camera and Drive Script
  Cam.active = true;
  DriveScript.active = true;
  
  //deactivating Player
  Player.active = false;
  yield WaitForSeconds(1);
  driving = true;
  }
 
 
 }


But if I deactivate the Player GameObject, I dont deactivate it's Children and it looks like the Player is standing next to the car, while he is driving it.

I also cant activate the Drive Script with this method.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by fafase · Aug 08, 2012 at 10:24 AM

Add a trigger around the car:

 var script:CarScript;
 function Start(){
   script= gameObject.getComponent(CarScript);
   script.enabled=false;}
 
 function OnTriggerEnter(other:Collider){
   if(other.gameObject.tag=="Player")script.enabled = true;}
 
 function OnTriggerExit(other:Collider){
   if(other.gameObject.tag=="Player")script.enabled = false;}

on the car script:

 var insideCar : boolean;
 var player :GameObject;
 function Start(){
   player =GameObject.Find("Player");
   insideCar = false;}

 function Update(){
   if(Input.GetKeyDown(KeyCode.E)){
     if(!insideCar){   // if not in the car
       player.transform.parent = transform;  // the player is attached to the car
       player.SetActiveRecursively(false);   // disable object and children of player
       Camera.main.transform.position = Vector3(camPositionBehindCar);// position the camera behind the car
       Camera.main.transform.parent = transform;  //Attach the cam to the car       
     }else{  // the player is inside we want to get out
       player.transform.parent = null; // the player is free to move   
       player.SetActiveRecursively(true); //the player and its children are activated
       Camera.main.transform.position = Vector3(camPositionBehindPlayer);// camera is positioned behind the player
       Camera.main.transform.parent = player.transform; //camera is attached to the player
     }
 }

I do not have Unity so it probably needs to be tried and fixed. But hopefully you get the idea.

Edit: I added the part for getting out. Still need to be confirmed.

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 DasFloX · Aug 08, 2012 at 04:53 PM

Oh Thanks, that is very helpful.

But unfortunately I still cant drive without activating the Drive Script somehow.

Comment
Add comment · Show 1 · 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 fafase · Aug 08, 2012 at 05:28 PM 0
Share

$$anonymous$$aybe you should put the script on the car. You could have the car script disabled so that it does not take any resources and a trigger around the car that enables the car script on enter and invert on exit.

From the car script you can control input and then disable your guy, attach the camera and so on.

avatar image
0

Answer by DasFloX · Aug 08, 2012 at 05:45 PM

I found the Answer,

 var DriveScript : MonoBehavior;

and then:

 DriveScript.enabled = 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 DasFloX · Aug 08, 2012 at 05:45 PM

How do I invert the effect of attaching the player to the car?

Comment
Add comment · Show 3 · 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 fafase · Aug 08, 2012 at 05:46 PM 0
Share

This should be a comment not an answer. That would avoid going through moderation.

avatar image DasFloX · Aug 08, 2012 at 05:56 PM 0
Share

okay, i'm new :D

avatar image fafase · Aug 08, 2012 at 06:02 PM 0
Share

No pb. I was new once. You could delete that "answers" and post your comments below the answer you are refering to. Fast and efficient

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

How to disable children triggering the collision event of parent. 1 Answer

Enable/Disable children / group of objects 0 Answers

is it possible to destroy the player and instantiate another controller? 1 Answer

Disabling audio Listener on the child of a newly instantiated gameObject? 0 Answers

Getting an objects Children 1 Answer


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