45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace CurvedUI
|
|
{
|
|
public class CUI_GunController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private CurvedUISettings ControlledCanvas;
|
|
|
|
[SerializeField]
|
|
private Transform LaserBeamTransform;
|
|
|
|
private void Update()
|
|
{
|
|
Ray ray = new Ray(base.transform.position, base.transform.forward);
|
|
if ((bool)ControlledCanvas)
|
|
{
|
|
CurvedUIInputModule.CustomControllerRay = ray;
|
|
}
|
|
float num = 10000f;
|
|
RaycastHit hitInfo;
|
|
if (Physics.Raycast(ray, out hitInfo, num))
|
|
{
|
|
int num2 = 0;
|
|
if (hitInfo.transform.GetComponent<CurvedUIRaycaster>() != null)
|
|
{
|
|
num2 = hitInfo.transform.GetComponent<CurvedUIRaycaster>().GetObjectsUnderPointer().FindAll((GameObject x) => x.GetComponent<Graphic>() != null && x.GetComponent<Graphic>().depth != -1)
|
|
.Count;
|
|
}
|
|
num = ((num2 != 0) ? Vector3.Distance(hitInfo.point, base.transform.position) : 10000f);
|
|
}
|
|
LaserBeamTransform.localScale = LaserBeamTransform.localScale.ModifyZ(num);
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
LaserBeamTransform.localScale = LaserBeamTransform.localScale.ModifyX(0.75f).ModifyY(0.75f);
|
|
}
|
|
else
|
|
{
|
|
LaserBeamTransform.localScale = LaserBeamTransform.localScale.ModifyX(0.2f).ModifyY(0.2f);
|
|
}
|
|
}
|
|
}
|
|
}
|