Easy Custom Cross Hair

paulgswansonpaulgswanson Posts: 95Member
edited October 28 in Scripts & Mods
This is an easy script to switch out the Default cross hair with a special one for the weapon.
This script goes on your Weapon object that's placed in the player hierarchy.

Player
| FPSCamera
| WeaponCamera
| 0Gun ----- It goes here'

I wont take credit for the original idea, this was based entirely on @redhawk 's Sniper Script.
Now I know there is certainly a better way to do this, this way is actually pretty slow. But it DOES work.
using UnityEngine;
using System.Collections;

public class CustomCrosshair : MonoBehaviour
{
//DefaultCrosshair
public Texture DefaultCrosshair = null;//Default Crosshair - use UFPS
public Texture CustomWeaponCrosshair = null;//Sniper Crosshair - make your own
protected vp_FPPlayerEventHandler m_Player = null;
protected vp_SimpleCrosshair m_crosshair = null;

protected virtual void Awake()
{
m_Player = GameObject.FindObjectOfType(typeof(vp_FPPlayerEventHandler)) as vp_FPPlayerEventHandler; // cache the player event handler
m_crosshair = GameObject.FindObjectOfType(typeof(vp_SimpleCrosshair)) as vp_SimpleCrosshair; // cache the Simple Crosshair
}

void OnGUI()
{
m_Player.Crosshair.Set(CustomWeaponCrosshair);
}
}

Comments

  • redhawkredhawk Posts: 489Member, MPTester
    Yea, that script is really old. You could probably just ignore the awake piece, do everything in OnEnable and OnDisable plus not doing the findObectOfType... just assume it exists in the Parent...
Sign In or Register to comment.