- Home /
Unity 2d select game object with keyboard
hey guys, I'm currently learning unity for a school project to build a game about space. The problem that I want to select the plants and align them with their orbit with the keyboard. this is my code and thanks.
pragma strict
var mercury = GameObject.FindWithTag ("mercury"); var venus = GameObject.FindWithTag ("venus"); function Start(){
} function Update () {
if(Input.GetKeyDown(KeyCode.Escape)){
mercury.gameObject.SendMessage("Activate");
venus.gameObject.SendMessage("Desactivate");
}
if(Input.GetKeyDown(KeyCode.Space)){
venus.gameObject.SendMessage("Activate");
mercury.gameObject.SendMessage("Deactivate");
}
} var inputEnabled : boolean = false;
// Update is called once per frame function mov () {
if(inputEnabled == true){
(Input.GetKeyDown(KeyCode.LeftArrow));{
transform.Translate(Vector3(-1,0,0));}
}
}
function Activate(){
inputEnabled =true;
}
function Deactivate(){
inputEnabled =false;
}
Answer by LilGames · Apr 22, 2018 at 08:39 PM
Be more specific. What problem are you encountering?
btw, in programming, you have to be very careful about spelling and typos, eg: "Desactivate"
Answer by unity_LAfgjMs60GPE7w · Apr 22, 2018 at 09:02 PM
@LilGames thanks for responding I am a beginner with unity, the problem that I want to select a specific planet with keyboard and move it ( with keyboard also ) to the orbit. it shows me a code error UnassignedReferenceException: The variable has not been assigned
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Issues with Input.inputString 2 Answers
Help with Virtual Keyboard 0 Answers
Key not recognized 2 Answers