GunAim.cs
815 Bytes
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
39
40
41
42
43
44
using UnityEngine;
using System.Collections;
public class GunAim:MonoBehaviour
{
public int borderLeft;
public int borderRight;
public int borderTop;
public int borderBottom;
private Camera parentCamera;
private bool isOutOfBounds;
void Start ()
{
parentCamera = GetComponentInParent<Camera>();
}
void Update()
{
float mouseX = Input.mousePosition.x;
float mouseY = Input.mousePosition.y;
if (mouseX <= borderLeft || mouseX >= Screen.width - borderRight || mouseY <= borderBottom || mouseY >= Screen.height - borderTop)
{
isOutOfBounds = true;
}
else
{
isOutOfBounds = false;
}
if (!isOutOfBounds)
{
transform.LookAt(parentCamera.ScreenToWorldPoint (new Vector3(mouseX, mouseY, 5.0f)));
}
}
public bool GetIsOutOfBounds()
{
return isOutOfBounds;
}
}