How would I use my right mouse button to turn a player character in Unity, while only turning in the direction and speed of the drag?
The game is 3D and you should hold down right click and drag to turn the camera.
Here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Control : MonoBehaviour {
public int speed;
public Transform tf;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(1))
{
tf.eulerAngles = new Vector3 (0, Input.GetAxis("Mouse X") * speed, 0);
}
}
}
The code above works, but after moving the mouse in the specified direction the character jumps back to its original position and kind of does this glitchy turn while moving the mouse (keeps jumping back to original position).
if(Input.GetMouseButton(0))
statement should do the trick. You could then just multiply aspeed
variable, byInput.GetAxis("MouseX")
and use the product to turn your player on an axis ;) \$\endgroup\$