- Home /
Function reload doesnt work
The function reload , isnt take as a function and console give me errors
var municion : int = 60;
var municiontotal = 300;
var guimuni : GUIText;
var guitotal : GUIText;
var destello : GameObject;
var manoanim : GameObject;
var municionanim : GameObject;
var Effect : Transform;
var TheDammage = 100;
function Start(){
destello.active = false;
}
function Update(){
guimuni.text = municion.ToString();
guitotal.text = municiontotal.ToString();
if(Input.GetMouseButton(0)){
if (municion > 0 && municiontotal >= 0){
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetButton("Fire1"))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
if(Input.GetKeyDown("r") && municiontotal > 0){
manoanim.animation.Play();
municionanim.animation.Play();
municion = 0;
Invoke ("reload",2);
}
if(Input.GetMouseButtonDown(0)){
destello.active = true;
}
else
if(Input.GetMouseButtonUp(0)){
destello.active = false;
}
if (municion <= 0){
destello.active = false;
}
}
function reload ()
{
if(municiontotal > 0){
municiontotal -= 60;
municion +=60;
}
if (municion >60){
municion = 60;
}
}
}
Comment
Best Answer
Answer by robertbu · Jul 20, 2014 at 05:49 PM
You've nested your reload() function inside of your Update() function. You cannot nest functions in Unity. To fix, move the '}' on line 75 to just above the reload() function.
Note using proper indentation will make issues like this one pop out.
Your answer
Follow this Question
Related Questions
Wait to Reload 2 Answers
Trouble With Disableing a Function 1 Answer
Change Automatic to Semi-Automatic 1 Answer
Unity White Screen Problem 2 Answers