I’m new to writing code, but with the help of a few tutorials I have a tolerable understanding of it. That said, the code I have tried to write wont attach to game objects due to compile errors that I don’t understand.
Here is the code
var casttime = 4.0;
var manacost = 25.0;
var projectile : Rigidbody;
var initialSpeed = 35.0;
function StartCastOne()
{
if (Input.GetKeyDown("1") mana>manacost)
{
yield WaitForSeconds (casttime);
PreparedSpellOne();
}
else return;
}
PreparedSpellOne();
{
if (Input.GetKeyDown("Fire1"));
{
BroadcastMessage ("CastSpellOne")
}
}
CastSpellOne()
{
// functional portion of spell
var instantiatedProjectile : Rigidbody = Instantiate (projectile,
transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(
Vector3 (0, 0, initialSpeed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
SendMessageUpwards("ApplyManaLoss", manacost,
SendMessageOptions.DontRequireReceiver);
}
If anybody could tell me what I’m doing wrong, I would be very grateful.
Just a helpful tip for compiler errors: when they pop up on the debugger, double click the error and it will bring up the offending script at the line that is causing the error, making it easier to track them down.
Oh good stuff. I just did a test and that trailing semi-colon on the “if” condition is definitely a culprit. In UnityScript it causes a compile error. In actualECMAScript/JavaScript/ActionScript it is valid (albeit pointless) compilable syntax.
EDIT: Also, the variable “mana” in your first “if” condition has not been declared.
Ok, first, thank you all for your help, I was surprised at how prompt a response you all gave.
Now the compile error with that script are fixed, well almost all of them.
As FizixMan pointed out, mana isn’t declared in this function. It’s declared in a function that is parent to this object. How could I call up the mana variable from the parent object?