Hello!
Im currently working on my first ever unity game, and i need help with a problem.
I want to be able to press a button, which will make a other object move.
Example: pressing an arrow, and a cube moves across the screen. I have the «move» script. But how do i activate it when the arrow is pressed.
Thanks
Hello,
you can look on youtube on unity how to move objects with a button And you can make the button for example an arrow
idk if this helps because i also currenly making my first own game
best regards Xavier
If by “arrow” you mean an arrow key on the keyboard, use GetKeyDown
if (Input.GetKeyDown(KeyCode.RightArrow))
{
Debug.Log("Right arrow key pressed. Add some cube movement code or whatever here");
}
If you instead mean a UI button with an image of an arrow, you would use the UI system.
https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/index.html
Any UI tutorial will cover how to create a button which calls your own function.
You can add the script on youre canvas and inside ure c# file enter something like this example if you make a public void name() And on the button make a new On click() .Then you move the canvas to below Runtime Only and then you search in the other slot for SceneSwitcher2 then another window opens en you select LevelSelect1
The name off SceneSwitcher2 and LevelSelect is then what you wrote down for example if you type in the code instead of SceneSwitcher2 Test and for LevelSelect1 Test1 then its gonne be Test then that other window opens and you click on Test1 i hope you can understand this because my english is not 100% best regards Xavier
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class SceneSwitcher2 : MonoBehaviour {
public void LevelSelect1()
{
SceneManager.LoadScene ("MainMenu");
}
}