- Home /
Gui texture
Hey, how to make a sniper rifle sight when you press the right mouse button
Do you know any scripting? Do you know how unity basically works? If so the answer is simple, if not you need to do allot more research before asking this question.
Answer by Benproductions1 · Feb 14, 2013 at 10:42 PM
Im assuming you know at least something about unity. You know how to do very basic scripts. You know how to add them to objects and set variables. You have a scope texture.
Here is the simple Answer:
var Scope:Texture2D; //The Scope Texture
private var ScopedIn:boolean = false;
function Update() {
if (Input.GetButton("Fire2")) { //Check for left mouse button, set ScopedIn to true else false
ScopedIn = true;
}
else {
ScopedIn = False;
}
}
function OnGUI() {
if (ScopedIn) { // Check if scoped in
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), Scope); //Draw Scope
}
}
Hope this helps, Benproductions1
Answer by gsoft9999 · Feb 14, 2013 at 11:41 PM
when you press a button I would display a textureGUI on the main camera and i would move my camera to a rifle or another way is to make a second camera and call it something like rifle sight , add texture and then switch between the cameras. but creating two cameras i think is easier than moving it. this is the script you need to add it to your scene on any object,this is javascript:
//start
function Update () { if(Input.GetButtonDown("Jump")){ Camera.main.depth=-10; } if(Input.GetButtonUp("Jump")){ Camera.main.depth=10; } }
//end
so if your new to unity then look for your project panel and there should be a button named create click it and then click on javascript. this will create a new java script open it and paste the code above
Your answer
Follow this Question
Related Questions
Instantiate bullet in time interval for "rifle". 2 Answers
Sniper Scope With GUI Texture 2 Answers
Mecanim and body orientation 0 Answers
How do I make a look at over time button for Oculus rift and Gear VR? 0 Answers
Scoping For Snipe Rifle 1 Answer