- Home /
Crosshairs change when sprinting?
This script adds a crosshair texture in the middle of my screen and then hides it if the right mouse button is being held down. Im trying to change the crosshair when the player is sprinting, but Im not sure what to put in my update, can anyone help me out?
var crosshairTexture : Texture2D;
var sprintCrosshairTexture : Texture2D;
var position : Rect;
var rightClick : boolean = true;
function Start(){
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}
function Update() {
if(Input.GetButtonDown("left shift")){
//texture change to sprint texture
}
if(Input.GetButtonUp("left shift")){
//texture change back to normal texture
}
if(Input.GetMouseButtonDown(1)){
rightClick = false;
}
if(Input.GetMouseButtonUp(1)){
rightClick = true;
}
}
function OnGUI(){
if(rightClick){
GUI.DrawTexture(position, crosshairTexture);
}
}
Answer by Griffo · Oct 13, 2012 at 12:48 PM
OK try this ..
var crosshairTextureBig : Texture2D;
var crosshairTexture : Texture2D;
var sprintCrosshairTexture : Texture2D;
var position1 : Rect;
var position2 : Rect;
var rightClick : boolean = true;
var shiftButton : boolean = fasle;
function Start(){
position1 = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
position2 = Rect( ( Screen.width - crosshairTextureBig.width ) / 2, ( Screen.height - crosshairTextureBig.height ) / 2, crosshairTextureBig.width, crosshairTextureBig.height );
}
function Update() {
if(Input.GetButtonDown("left shift")){
shiftButton = true;
}
if(Input.GetButtonUp("left shift")){
shiftButton = false;
}
if(Input.GetMouseButtonDown(1)){
rightClick = false;
}
if(Input.GetMouseButtonUp(1)){
rightClick = true;
}
}
function OnGUI(){
if(rightClick){
GUI.DrawTexture(position1, crosshairTexture);
}
if(shiftButton){
GUI.DrawTexture(position2, crosshairTextureBig);
rightClick = false;
}
if(!shiftButton){
GUI.DrawTexture(position1, crosshairTexture);
}
}
I get errors saying unknown identifier position1, position2 and position3 can you help please?
oh there's no position3, ive just added a few more variables and I solved it. But when I hold the right mouse button my crosshairs still show and ins$$anonymous$$d of changing the crosshair when the left shift is held down it overlaps both of the textures.
It still shows when ai$$anonymous$$g in and overlaps when sprinting.
Answer by Griffo · Oct 13, 2012 at 12:07 PM
Something like
function Update() {
if(Input.GetButtonDown("left shift")){
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width * 2, crosshairTexture.height * 2 );
}
if(Input.GetButtonUp("left shift")){
position = Rect( ( Screen.width - crosshairTexture.width ) / 2, ( Screen.height - crosshairTexture.height ) / 2, crosshairTexture.width, crosshairTexture.height );
}
Or ..
crosshairTexture.width + 10, crosshairTexture.height + 10
Ins$$anonymous$$d of changing the crosshair when scripting is there a way to hide it as well as when ai$$anonymous$$g in?