Hiya , me gun shots and shot very fine but not counting bullets , no stop when bullets clips empty, and no recharging…whaty i doing wrong???, please need a hand thank you in advance!!!
#pragma strict
///private var anim : Animator;
var Effect : Transform;
var TheDammage = 100;
var fireRate : float = 0.5;
///private var lastShot = -3.0;//Dont touch! si quiero activar tiempo disparos
private var nextFire : float = 0.0;
private var reloading = false;
var reloadTime = 2.0;
private var st : int;
var clipAmmo = 50;
var clipSize = 50;
var stockAmmo = 100;
function Update () {
Fire ();
}
function Fire () {
if(Input.GetButton("Fire1") && Time.time > nextFire) {
nextFire = Time.time + fireRate;
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.64, Screen.height*0.4, 0));
if(Input.GetButton("Fire1"))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 1);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
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(stockAmmo >neededAmmo){
clipAmmo = clipSize;
stockAmmo -= neededAmmo;
}else if(stockAmmo <= neededAmmo){
clipAmmo += stockAmmo;
stockAmmo = 0;
}
}
reloading = false;
}
function SaveTime(time){
st = reloadTime + Time.time;
Dantus, yes , i dont know very mutch about coding, and this is the reason why i asking the people like you and the other a little help…i dont want you to make the work for me, i try it hard but cant do it, i aks a little help nothing else, if you dont want ho help me out , i undestand, and say thanks for that.In one of your replyes you suggest some modifies but i try it to do it and no result, if if very hard work to show me a few new line codes for make the script work…it all right.I surrender.If not and sombody can genty want to write this few lines for me so i can lear from that i be glad.
LeftyRight, thanks for the reply, yes somtimes when we want to make somthing we do some stupid things like me and duplicate the threads, i just want a little help in this and learn from it, i apreciate if sombody can ad the solution to the script so i can learn more quick than other ways, of course i apreciate the link you provide to star learning more.
If you can helpme , please do it , if not , i apreciate anyway.
What you are asking for is relatively simple. It is simple enough that someone who understands the basics of coding should be able to at least give it a try. Unfortunately, it seems you don’t understand the basics well enough yet. The best tip I can give you is, learn the basics first.
To make an analogy. You are in a survival game and you want to build a house, but unfortunately you neither have the needed tools and resources yet, nor the experience that is needed. The helping hand would just do the work for you and you could hardly follow. At least I don’t have the required time to guide you through it.
There are a lot of online tutorials where you can learn the basics.