summaryrefslogtreecommitdiff
path: root/GameCode/Aim.cs
blob: 45288a589610d237e9fdb90cb0ab32ca410d903b (plain)
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
using UnityEngine;

public class Aim : MonoBehaviour
{
	private GeneralInput input;

	private HoldingObject holdingObject;

	private CharacterData data;

	private Vector3 aimDirection;

	private void Awake()
	{
		input = GetComponent<GeneralInput>();
		data = GetComponent<CharacterData>();
		holdingObject = GetComponentInChildren<HoldingObject>();
	}

	private void Update()
	{
		if ((double)input.aimDirection.magnitude > 0.2)
		{
			aimDirection = input.aimDirection;
		}
		if (input.direction.magnitude > 0.2f && Optionshandler.leftStickAim && input.aimDirection == Vector3.zero)
		{
			aimDirection = input.direction;
		}
		if ((bool)holdingObject)
		{
			if (aimDirection != Vector3.zero)
			{
				holdingObject.transform.rotation = Quaternion.LookRotation(aimDirection);
			}
			data.aimDirection = aimDirection;
		}
	}
}