|
i made a sniper, i can right click and it zooms in, then i let go and it zooms out but i want it to have like a screen where only that zooms in more like i think i have to have a plane, and then add something to that plane that shows an image from something else
(comments are locked)
|
|
You must use a second camera childed to the weapon to show the zoomed image (set Field of View to a small angle - 15 to 30 - to zoom). In this case, the scope body is a 308x308 PNG texture with transparency (see credit and reference at the page foot), and the center area can hold a camera image of 196x196 pixels. You can bring the weapon to the aim position and enable the camera and texture drawing with something like this:
var texScope: Texture; // drag the scope image here
var scopeCam: Camera; // drag the scope camera here
var rCamera = Rect(0, 0, 196, 196);
var rScope = Rect(0, 0, 308, 308);
var enableAim: boolean = false; // set enableAim to true to aim
function OnGUI(){
if (enableAim){
rCamera.x = (Screen.width - rCamera.width)/2; // center rCamera
rCamera.y = (Screen.height - rCamera.height)/2;
rScope.x = (Screen.width - rScope.width)/2; // center rScope
rScope.y = (Screen.height - rScope.height)/2;
scopeCam.pixelRect = rCamera;
scopeCam.enabled = true;
GUI.DrawTexture(rScope, texScope, ScaleMode.ScaleToFit, true, 0);
}
else {
scopeCam.enabled = false;
}
}
function Update(){
enableAim = Input.GetMouseButton(1); // aim while the right mouse button is pressed
}
CREDIT/REFERENCE: The scope image above was captured from the game EliteSquad (2nd liked video), created by leonardotry, and edited to make transparent the undesired areas. You can download it for testing purposes - (click here to download). "thanks but this is for pixelrect, could you show me how to do the rendertexture, ive been looking for it for a while (i have pro)": 1- Create a new Render Texture asset using Assets->Create->Render Texture; Hope this will work fine (even because I can't help too much without a Pro).
Oct 19 '11 at 11:21 AM
aldonaletto
The script works beautiful many thanks!
Jan 29 at 04:02 PM
shrooster
(comments are locked)
|

