- Home /
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
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
Thank you but how would i assign that to a car when the main character get in the car?
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!!!!!
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?
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
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)?
Your answer
Follow this Question
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