Hi, I want to make my character’s camera moves with mouse movement but only while right clicking.
I’ve tryed this:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(1))
{
Input.GetAxis(“MouseX”);
Input.GetAxis(“MouseY”);
}
}
}
MouseX and MouseY in InputManager:
It does nothing when right-clicking. Am I missing something or doing something wrong?
x3r
2
Simple example,so you can see how its done…There’s plenty examples on internet.
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
private float mouseHorizontal;
private float mouseVertical;
private Quaternion camRotation;
// Use this for initialization
void Start () {
playerCam = GetComponent<Camera>();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(1))
{
mouseVertical -= Input.GetAxis("Mouse Y") * Time.deltaTime * 100f;
mouseHorizontal += Input.GetAxis("Mouse X") * Time.deltaTime * 100f;
camRotation = Quaternion.Euler(mouseVertical, mouseHorizontal, 0f);
playerCam.transform.rotation = camRotation;
}
}
}
It simply rotate camera hori/vert as for fps cam.
1 Like