So this is your code:
public void ProcessInput()
{
float inputAxisX = Input.GetAxis("Horizontal");
if (inputAxisX == 0)
Debug.Log("AxisX = 0");
else
Debug.Log("Moving! " + inputAxisX);
bool isKeyDownJump = Input.GetButtonDown ("Jump");
bool isKeyDownLeft = inputAxisX < -0.5f;
bool isKeyDownRight = inputAxisX > 0.5f;
}
I’m assuming you want to make your Move move the character when isKeyDownLeft or isKeyDownRight is on, right?
Now I’m not sure what you mean by changing variables from a different method. Methods are like functions; if you want to give a function variables, you just send it arguments. From what you want it seems like you need code to go from one script to another.
That is done in several ways - one is you could make the variables you need static, essentially telling Unity that those variables have one instance, and then you don’t need to specify the gameobject holding the script to change them because Unity just changes all of them, OR you will have copies of your script which will then be on a gameobject, which you can reference later. I’d assume as a starter you want the latter. First of all, the method you have needs to either return something or have the bools it changes outside of the method. Let’s say you have another script called “Player”. This script would look something like this:
public class Player : MonoBehaviour
{
public TouchController TouchCont;
Rigidbody2D charRB;
const float speed = 1.0f;
void Start ()
{
TouchCont = FindObjectOfType<TouchCont>();
charRB = GetComponent<Rigidbody2D>();
}
void Update()
{
if(TouchCont.isKeyDownLeft)
charRB.velocity = Vector2.left * speed;
else if(TouchCont.isKeyDownRight)
charRB.velocity = Vector2.right * speed;
else
charRB.velocity = Vector2.zero;
}
}
While a part of your original script would look something like this:
public class TouchController : MonoBehaviour
{
public bool isKeyDownJump, isKeyDownLeft, isKeyDownRight;
public void ProcessInput()
{
float inputAxisX = Input.GetAxis("Horizontal");
if (inputAxisX == 0)
Debug.Log("AxisX = 0");
else
Debug.Log("Moving! " + inputAxisX);
isKeyDownJump = Input.GetButtonDown ("Jump");
isKeyDownLeft = inputAxisX < -0.5f;
isKeyDownRight = inputAxisX > 0.5f;
}
void Update()
{
ProcessInput();
}
}
However, this is a really crappy implementation and not optimized. Before going further into creating your game, I’d advise you to go through Beginner, Intermediate and Editor scripting tutorials here Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn (top 3), watch them as many times as you need and hopefully you’ll be a better programmer. I didn’t add the jump movement but I think you’ll be able to fill in the blanks after watching the tutorials.