Hey guys,
I’m learning Unity (First game) and I am stuck.
I want to create a simple 2D topdown game zelda like.
I created a simple player controller through a script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private bool isMoving;
private Vector2 input;
void OnGUI()
{
Event e = Event.current;
if (e.isKey)
Debug.Log("e.keyCode: "+e.keyCode);
}
private void Update()
{
if (isMoving)
{
input.x = Input.GetAxisRaw("Horizontal");
input.y = Input.GetAxisRaw("Verical");
if (input != Vector2.zero)
{
var targetPos = transform.position;
targetPos.x += input.x;
targetPos.y += input.y;
StartCoroutine(Move(targetPos));
Debug.Log("it is working");
}
}
}
IEnumerator Move(Vector3 targetPos)
{
isMoving = true;
while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
{
transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
yield return null;
}
transform.position = targetPos;
isMoving = false;
}
}
It was working perfectly.
Then I tried to implement the new input system to learn how to use it.
Switched the player parameters “Active Input Handling”.
I was also perfectly working.
Then I switch back to the old input system.
Now I can’t move my player anymore.
On this project nor any new ones I create.
I don’t know what cause it. Is it the script, a corrupt package, the input system, the controller system, etc?
I also tried the following:
- Create a new project and strat again from scratch
- Restart Unity
- Restart the computer
- Delete all the cache
- Delete every single Unity files from the computer
- Unistall/Reinstall Unity
- Install a newer version (Unity 2022.3.40f1)
- Tried Active Input Handling with old system
- Tried Active Input Handling with new system
- Tried Active Input Handling with both system
I just don’t know what to try next to solve this problem.
Maybe it is just something to tick I don’t know about.
Some extra insight for the code:
I can see the log of the key press in the console but don’t have the “it is working” log.
Do you have any insight or recommandation?
Thanks for helping guys