This might sound a little nuts since I am not exactly sure how to explain things sometimes. lol
I have this crosshair script
using UnityEngine;
using System.Collections;
public class Crosshair : MonoBehaviour
{
public Texture2D crossHair;
void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2 - 18, Screen.height / 2 - 25, 100, 50), crossHair);
}
}
So when aim = true in this script
using UnityEngine;
using System.Collections;
public class FOVAim : MonoBehaviour
{
public GameObject aimCam;
public float fovAim = 35;
public float defFov;
public float aimSpeed = 5;
public bool aim = false;
void Start()
{
defFov = aimCam.camera.fieldOfView;
}
void Update()
{
if (Input.GetMouseButtonDown(1))
{
aim = true;
}
if (Input.GetMouseButtonUp(1))
{
aim = false;
}
if (aim == true)
{
aimCam.camera.fieldOfView = Mathf.Lerp(aimCam.camera.fieldOfView, fovAim, aimSpeed * Time.deltaTime);
}
if (aim == false)
{
aimCam.camera.fieldOfView = Mathf.Lerp(aimCam.camera.fieldOfView, defFov, aimSpeed * Time.deltaTime);
}
}
}
I want to turn off my crosshair because this is also when I turn on my Laser Sight
here is that script also if that helps
using UnityEngine;
using System.Collections;
public class LaserSight : MonoBehaviour
{
LineRenderer line;
private Light redDot;
void Start()
{
line = gameObject.GetComponent<LineRenderer>();
line.enabled = false;
redDot = gameObject.GetComponent<Light>();
redDot.enabled = false;
}
void Update()
{
if (Input.GetButtonDown("Fire2"))
{
StopCoroutine("FireLaser");
StartCoroutine("FireLaser");
}
}
IEnumerator FireLaser()
{
line.enabled = true;
redDot.enabled = true;
while(Input.GetButton("Fire2"))
{
Ray ray = new Ray(transform.position, transform.forward);
RaycastHit hit;
line.SetPosition(0, ray.origin);
if (Physics.Raycast(ray, out hit, 100))
line.SetPosition(1, hit.point);
else
line.SetPosition(1, ray.GetPoint(100));
yield return null;
}
line.enabled = false;
redDot.enabled= false;
}
}
If that makes any sense haha!
Thanks for any help and sorry if this is a long post.
I also take no credit for most of the code in the scripts it’s obvious of course.