Skip to main content

Posts

Showing posts with the label Input

Limiting Rotation of an Object

I made this script for my Beach Defender Game . It was to keep the player from rotating more than I want his to, because I'm a mean person like that. Any way it took me awhile to figure out how to not make them turn to far to the left, right, up, down.. You know. Here's the script. Pretty simple. Put under Update function. Feel free to suggest different ways. Or ask any questions. var upDown = Input.GetAxis("Vertical") *Time.deltaTime * (rotateSpeed-10); var leftRight = Input.GetAxis("Horizontal") * Time.deltaTime * (rotateSpeed-10); //making it turn up or down if(transform.localEulerAngles.x < 25 ){ transform.Rotate(upDown, 0, 0); } else if (transform.localEulerAngles.x > 295){ transform.Rotate(upDown, 0, 0); } //making it turn left or right if(transform.localEulerAngles.y < 65 ){ ...

Simple Reload Script

Sooo I'm working on a simple Top Down Shooter game. And This was the script I came up with for the reloading part of the script. Very simple. I think you can use it with any weapon really. You reload with space. You  need to put your own method of Firing in this script. Comment if you have any questions private var reloading = false; var reloadTime = 2.0; private var st : int; var clipAmmo = 50; var clipSize = 50; var stockAmmo = 100; function Update () { if (Input.GetKeyDown ("space")){ if(clipAmmo<clipSize && reloading == false && stockAmmo !=0){ SaveTime(Time.time); reloading = true; } } if(st < Time.time && reloading == true){ Reload(); } } //Making it show that you are reloading. function OnGUI(){ if(reloading == true){ GUI.Box(Rect(250,200,100,25),"Reloading"); } } function Reload(){ if(clipAmmo < clipSize){ var neededAmmo = clipSize-clipAmmo; if(stockA...