-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCameraScript.cs
More file actions
35 lines (28 loc) · 1.19 KB
/
CameraScript.cs
File metadata and controls
35 lines (28 loc) · 1.19 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
using UnityEngine;
using System.Collections;
public class CameraScript : MonoBehaviour {
public GameObject player;
private float camPosX = 30;
private bool isOrtho = false;
// Update is called once per frame
void Update ()
{
if (isOrtho)
{
Camera.main.transform.position = new Vector3(player.transform.position.x-10.0f, player.transform.position.y, player.transform.position.z+5.0f);
Camera.main.transform.rotation = Quaternion.Euler(new Vector3(0, 90f, 0));
if (Input.GetKeyDown(KeyCode.O))
isOrtho = false;
}
else
{
//Positions the camera above and behind the player object
Camera.main.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + 1.0f, player.transform.position.z - 1.0f);
//Rotates the camera according to the rotation values of the player object
Camera.main.transform.rotation = Quaternion.Euler(new Vector3(camPosX, player.transform.eulerAngles.y, 0));
//Press "O" to go into Orthographic View
if (Input.GetKeyDown(KeyCode.O))
isOrtho = true;
}
}
}