Unity version:2021.1.24f1
Hello, currently I am creating a 2D game with Unity 3d; I wish that when I click with my mouse and the cursor is above my sprite it goes up 15 pixels; it moves vertically and horizontally
My script:
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
Rigidbody m_Rigidbody;
float m_speed;
void Start(){
m_Rigidbody = GetComponent<Rigidbody>();
m_speed = 5f;
}
void Update()
//bouton gauche de la souris
{if (Input.GetMouseButtonDown(0)){
m_Rigidbody.velocity = transform.forward(new Vector2(0,-1) * Time.deltaTime * m_speed, Space.World);
}
//bouton droit de la souris
if(Input.GetMouseButtonDown(1)){
m_Rigidbody.velocity = transform.forward(new Vector2(-1, 0) * Time.deltaTime*m_speed, Space.World);
}
//roulette de la souris
if(Input.GetMouseButtonDown(2)){
m_Rigidbody.velocity = transform.forward (new Vector2(0,-1) * Time.deltaTime * m_speed, Space.World);
}
}
}```