V
V
Vladecmolodec2019-10-12 03:16:02
C++ / C#
Vladecmolodec, 2019-10-12 03:16:02

C# How to remap a key click (left-right) to a touch on an object on the screen (for example, a left-right arrow)?

Script for the character, namely - the part related to movement

public class MovePlayer : Unit

private void Update() 
    {
        if (Input.GetButton("Horizontal")) Run();
    }

private void Run() // 
    {
        Vector3 direction = transform.right * Input.GetAxis("Horizontal"); 

        transform.position = Vector3.MoveTowards(transform.position, transform.position + direction, speed * Time.deltaTime); 

        sprite.flipX = direction.x < 0f; 
    }

Script for Arrows. The click check works, it remains to somehow connect it with the Run method or even enter the object into the script for the character ...
public class Touch : MonoBehaviour
{
    void Start()
    { 
 
    }
    
    void OnMouseDown()
    {
        Debug.Log("OnMouseDown");
      }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question