Hello guys i have little problem. In my game i have 3 lines and 1 Player . Line-1 is left , Line0 is starting Line and she is in middle of the screen, Line 1 is right. I need that when I click on A, the Player moves from Line0 to Line-1 when I click on D so the player moves from Line-1 to Line0 and again clicks D to move from Line-0 to Line1. I dont know how to script it. THX for every answer. Here is Link https://ibb.co/fWLKSx
You can try with array. Add this script to player. Drag&drop your lines from the scene into this script (fill the array with lines from left to right). Set the number for first line (beginn with 0). Code (CSharp): //array with lines positions public Transform [] Lines; //first line where player will be at start (beginns with 0) public int playerLine; void Start () { //check that index isn't out of range (as example: your 3 lines will be indexed as 0, 1, 2) playerLine = Mathf.Clamp(playerLine, 0, Lines.Length - 1); //place player at needed line transform.position = new Vector2(Lines[playerLine].position.x, transform.position.y); } void Update () { //check if D is pressed if (Input.GetKeyDown(KeyCode.D)) { //increase the index at one playerLine = playerLine + 1; //check that new index can be out of range if greater as lenght of array -1 if (playerLine >= Lines.Length) //as said the index beginns with zero. The last line will have index: lenght of array - 1 playerLine = Lines.Length - 1; //move player at new line transform.position = new Vector2(Lines[playerLine].position.x, transform.position.y); } //check if A is pressed if (Input.GetKeyDown (KeyCode.A)) { //decrease the index at one playerLine = playerLine - 1; //check that new index isn't lower as 0 if (playerLine < 0) //set index to zero playerLine = 0; //move player at new line transform.position = new Vector2(Lines[playerLine].position.x, transform.position.y); } } And then check the unity tutorials https://unity3d.com/learn/tutorials