Hey guys, I’m fairly new to Unity. I’ve been playing around with the 2D editor and scripting with C#. I’ve run into a bit of a snag with my current project. I’m trying to create a top-down movement style similar to Pokemon or Final Fantasy.
Here’s what I have so far:
{
public float speed = 2.5f;
bool canMove;
Vector3 pos;
Transform tr;
void Start ()
{
bool canMove = true;
}
void Movement ()
{
if (Input.GetKey (KeyCode.W))
{
transform.Translate(Vector3.up * speed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.A))
{
transform.Translate(Vector3.left * speed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.S))
{
transform.Translate(Vector3.down * speed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.D))
{
transform.Translate(Vector3.right * speed * Time.deltaTime);
}
}
void FixedUpdate ()
{
if (canMove = true)
{
Movement ();
}
}
}
I should also mention that I found a JavaScript code that worked exactly how i wanted it to somewhere amongst the interwebs, but I’m completely illiterate with JavaScript so I’ve been trying to recreate it in C#.
