MainCameraMouse.cs
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MainCameraMouse : MonoBehaviour {
private Transform myTransform;
public float rotateSpeed;
// Use this for initialization
void Start ()
{
myTransform = GetComponent<Transform>();
}
// Update is called once per frame
void Update ()
{
Vector3 targetRotateVectorLeft = new Vector3(myTransform.rotation.x, -rotateSpeed, myTransform.rotation.z);
Vector3 targetRotateVectorRight = new Vector3(myTransform.rotation.x, rotateSpeed, myTransform.rotation.z);
Vector3 targetRotateVectorUp = new Vector3(rotateSpeed, myTransform.rotation.y, myTransform.rotation.z);
Vector3 targetRotateVectorDown = new Vector3(-rotateSpeed, myTransform.rotation.y, myTransform.rotation.z);
if (Input.GetKey(KeyCode.A))
{
myTransform.Rotate(Vector3.Lerp(myTransform.rotation.eulerAngles, targetRotateVectorLeft, 10f));
}
else if (Input.GetKey(KeyCode.D))
{
myTransform.Rotate(Vector3.Lerp(myTransform.rotation.eulerAngles, targetRotateVectorRight, 10f));
}
else if (Input.GetKey(KeyCode.W))
{
myTransform.Rotate(Vector3.Lerp(myTransform.rotation.eulerAngles, targetRotateVectorUp, 10f));
}
else if (Input.GetKey(KeyCode.S))
{
myTransform.Rotate(Vector3.Lerp(myTransform.rotation.eulerAngles, targetRotateVectorDown, 10f));
}
}
}