Okay, im still a bit new to unity but help a rookie out. Im making a fan made Star Trek game and for the ship im currently using the ShipControls Script from the wiki. How can I adapt this script to allow height change and program keys for one-press activate (eg: +=move forward -=stop and r=reverse w=down s=up (a and d are programed how I want))
People probably aren’t going to do the work for you. If you plan on making a game of any sort, you will need to learn to make scripts yourself.
I suggest going through the tutorials over here. Go through the 2D game tutorial and the 3D fps tutorial, read the scripts and learn how they work. Also, look into the Unity documentation here for more information.
Okay, on something different, I want to be able to switch between 2 ships, The code I have here switches the camera, but not the control of the ship. Also, when it switches, I only want to disable the game object and NOT the children. Can anyone help me?
var camera1 : GameObject;
var camera2 : GameObject;
var gameobject1 : GameObject;
var gameobject2 : GameObject;
function Start () {
camera1.camera.enabled = true;
camera2.camera.enabled = false;
gameobject1.GameObject.enabled = true;
gameobject2.GameObject.enabled = false;
}
function Update () {
if (Input.GetKeyDown ("2")){
camera1.camera.enabled = false;
camera2.camera.enabled = true;
gameobject1.GameObject.enabled = false;
gameobject2.GameObject.enabled = true;
}
if (Input.GetKeyDown ("1")){
camera1.camera.enabled = true;
camera2.camera.enabled = false;
gameobject1.GameObject.enabled = true;
gameobject2.GameObject.enabled = false;
}
}
I guess you’re still using the code you attached to your first post? If so, you’ll notice that it contains things like “rigidbody.AddForce” and “transform.rotation”. These properties apply to the Rigidbody and Transform components attached to the object with the script. You can, however, refer to components on another GameObject. You need to use a variable to access the second object and then you can refer to its properties:-
var otherObject: GameObject; // Set this in the inspector, say...
...
otherObject.rigidbody.AddForce(...);
otherObject.transform.rotation = ...;
The code in the first post is for the control of the ship itself, I want to basically make the ship rotate around y axis and the z axis and change direction with rotation. The script in the first post is the one from the wiki for 2d ship controls, I basically want to add another rotation axis that rotates the ship, but only changes the ships position when the ship is moving forward. The other script is suppose to allow me to switch between two ships and cameras. Example:
Ship2:smile:ocked
Player flying ship 1
player needs ship 2 to do something #2 key pressed
Player enables other ship and camera while disabling the other ship WITHOUT deactivating the children attached to the previous ship. #1 key pressed
Player switches back to Ship1 and deactivates ship 2 and camera attached to ship2 but doesnt deactivate children of ship2
Basically the second script I posted should do that but, it only switches camera.
I think I’ve got what you are doing now. The ship control script has a playerControl variable that determines whether the ship will get input or not (have a look at the “if” statement at the top of the Update function). If you take the Input.GetAxis lines out of this “if” statement into the main body of the function, you should be sure the script will get input when it’s GameObject is enabled.