- Home /
How to enable/disable buttons when player enters/leaves area.
Hello guys,
My name is Nandor, and i'm a novice java scripter. I took schooling for Visual Basic programming, but i feel javascript is easier. Personal opinion :)
Anywho, down to brass tax. I am having a few issues, but i will stick to the one question this title entails. My current question/dilema is:
I am making a top down perspective game, where the player commands an individual unit, as well as a space ship. The player will have 2 modes, Ship Mode, and Commander Mode.
1) Ship Mode: Player presses a hotkey and the camera switches to Ship Command. In this mode, the player is able to fly the ship like any Space Sim, but he only has control over the movement.
2) Commander Mode: Player presses a hotkey and the camera switches to a top-down shooter view of the individual player. In this mode, the player will be able to walk around the interior of his fully customizable ship and fight off invaders internally, as well as repair, manually control, and switch ships to better assist in the battle.
In order for the player to hop into Ship mode, he/she needs to be in an area called the "Bridge". Now if you've seen the popular shows such as Stargate: Atlantis, and Stargate: SG1, this is where the Ships Commander is stationed in order to better organize and command his men. I would like to know if it is possible to create a script that does this:
When the player enters the bridge component(Placed somewhere on the ship by the player), certain hotkeys(Inputs) are enabled so he/she is able to switch modes. (From top down shooter of individual unit, to top down exterior of ship) When he presses another button, and leaves the bridge, the hotkeys(Inputs) are disabled and the controls and camera's switch to commander mode, where he is free to roam the interior of his/her ship(also custom designed by the player).
The script i have so far is:
var shipCamera: Camera;
var commanderCamera: Camera;
var testCamera : Camera;
var target: Transform;
var prefab : Transform;
function Start ()
{
shipCamera.enabled = false; commanderCamera.enabled = true; testCamera.enabled = false;
}
// Instantiates prefab when any rigid body enters the trigger.
//it preserves the prefab's original position and rotation.
function OnTriggerEnter (target)
{
if (Input.GetKeyDown ("2"))
{
shipCamera.enabled = false; commanderCamera.enabled = true; testCamera.enabled = false;
}
if (Input.GetKeyDown ("3"))
{
shipCamera.enabled = false; commanderCamera.enabled = false; testCamera.enabled = true;
}
if (Input.GetKeyDown ("3"))
{
shipCamera.enabled = false; commanderCamera.enabled = false; testCamera.enabled = true;
}
if (Input.GetKeyDown ("1"))
{
shipCamera.enabled = true; commanderCamera.enabled = false; testCamera.enabled = false;
}
}
function OnTriggerExit(target)
{
}
Now this is what i have to work with so far, its just the camera script, but i was thinking, if i added it directly into the camera script, it would tied into the cameras directly, making altering them easier.
As i said before, i am a GREAT noob to programming, :( But i want to learn! If there is any way any of you guys can help me out here, and get me on track, that would be GREAT!
I thank you for reading, Sincerely, Nandor.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063842im_/https://answers.unity.com/themes/thub/images/avi.jpg)