Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Rob9891 · Sep 29, 2011 at 11:24 PM · gamecargta

gtting in a car and radio stations

Yes i am going to learn more about unity before i try this but i want to take notes on this so when im ready i can do it. So how would i get the main character to be able to get into a car? I figured i could use raycast to see if a car is close enough then press a key and play an animation with the main character getting in the car. But i dont know how to write a script like that. Can someone help me? and radio stations to

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

2 Replies

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

Answer by Grady · Sep 30, 2011 at 11:07 AM

Basically, the steps that I would take would be to, first have your character model. then get all the animations for it to walk around. Then you need an animation for it to open a car door, or if it is an open vehicle like a buggy or something, then just have an animation for the player getting into the seat. Obviously you would need a setup so that when the player enters the car, the control changes from the characters walk around script to the car driving script

Then what I would do for radio stations, is get each different radio station into it's own single audio file, so if you had five radio stations, then you would have five audio files, where each different audio file is each different radio station. Then have a script that is set so that when the player hits the "change radio" button, it goes from one audio file to another.

That script might look something like this:

 private var radioStation = "off";
 
 function Update()
 
     if(Input.GetKeyDown("tab")){
     
         if(radioStation == "off"){
             radioStation = "station1";
         }
         else if(radioStation == "station1"){
             radioStation = "station2";
         }
         else if(radioStation == "station2"){
             radioStation = "station3";
         }
         else if(radioStation == "station3"){
             radioStation = "station4";
         }
         else if(radioStation == "station4"){
             radioStation = "station5";
         }
         else if(radioStation == "station5"){
             radioStation = "off";
         }
 
     if(radioStation == "station1"){
     //PLAY STATION ONE FILE HERE
     }
         else if(radioStation == "station2"){
     //PLAY STATION TWO FILE HERE
     }
         else if(radioStation == "station3"){
     //PLAY STATION THREE FILE HERE
     }
         else if(radioStation == "station4"){
     //PLAY STATION FOUR FILE HERE
     }
         else if(radioStation == "station5"){
     //PLAY STATION FIVE FILE HERE
     }
 }

Hope this has helped you get an idea...

Feel free to comment back if you have any questions!!!!

-Grady

Comment
Add comment · Show 6 · 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 Rob9891 · Sep 30, 2011 at 05:18 PM 0
Share

Thank you but how would i assign that to a car when the main character get in the car?

avatar image Grady · Oct 02, 2011 at 01:02 AM 0
Share

you would need to have a variable, something like: inCar and set that to false when player is out of the car and true when the player is in. Then say, if inCar equals true, then do the script above that will allow you to change the radio!!!!!

avatar image Rob9891 · Oct 02, 2011 at 03:42 PM 0
Share

Thank you so much!!! This is my last question on this subject whats a script that would allow the character to play the animation and get in the car?

avatar image Rob9891 · Oct 02, 2011 at 03:44 PM 0
Share

And if theres a ped in there how would i play an animation of the main character draggin them out o the car? thank you in advance

avatar image john-essy · Oct 02, 2011 at 04:08 PM 0
Share

You will need a character with the animations

Show more comments
avatar image
0

Answer by Ayman493 · Mar 11, 2013 at 02:23 PM

It would be more realistic if all radio stations were playing constantly, but the inactive ones have volume set to zero and the one that is active has its volume up. This is because in real life (and GTA), radio stations continue even when switched off. I made it work perfectly in the Scratch Programming Language. What about Unity (C#/Javascript)?

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

7 People are following this question.

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

Related Questions

Camera position/rotation reset after 5 seconds of mouse inactivity 0 Answers

Getting in a car 2 Answers

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

How to get rid of lines on terrain? 2 Answers

Problem with jcar script for android mobile 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