J
J
Jacon2021-07-27 01:08:16
C++ / C#
Jacon, 2021-07-27 01:08:16

How to make a character in unity2d move the other way?

How to change the character controller so that it moves along the x axis?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    private Vector2 targetPos;
    public float Yincrement;

    private void Update()

    {
        if(Input.GetKeyDown(KeyCode.W))
        {
            targetPos = new Vector2(transform.position.x, transform.position.y + Yincrement);
            transform.position = targetPos;
        }
        else if(Input.GetKeyDown(KeyCode.S))
        {
            targetPos = new Vector2(transform.position.x, transform.position.y + Yincrement);
            transform.position = targetPos;
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Polishchuk, 2021-07-27
@PNECtarine

Change the position of "x"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question