I want to save the basic 2D control for a character that the user provides before starting the time in scene.
and can anyone help me by telling the way by which i can move my character according to the input in array.
i’ve made a code but i am sure it doesn’t work but it explains the point well.
using UnityEngine;
using System.Collections;
public class charactercontrol : MonoBehaviour {
// Use this for initialization
void Start () {
int[] instructions = new int[25];
}
// Update is called once per frame
void Update () {
for (int i = 0; i < 5; i++)
if (Input.GetKey ("up")) {
instructions *= 1;*
_ instructions = 2;_
* }*
* else if (Input.GetKey (“down”)) {*
_ instructions = 3;
* }
else if (Input.GetKey (“left”)) {
instructions = 4;
}
}
}*_
I think you are on the right way.
Use a list to store the inputs, then make a switch to check each key
// Inputs list
public List<string> inputKeys = new List<string>() ;
void Update(){
if(Input.GetKeyDown("down")){
inputKeys.Add("down") ;
}
if(Input.GetKeyDown("right")){
inputKeys.Add("right") ;
}
if(Input.GetKeyDown("left")){
inputKeys.Add("left") ;
}
if(Input.GetKeyDown("up")){
inputKeys.Add("up") ;
}
// Check the list and do whatever you want for each key string
foreach(string key in inputKeys){
switch(key){
case "down" :
break ;
case "up" :
break ;
case "right" :
break ;
case "left" :
break ;
}
}
}