First, let me recommend that you ditch JS and learn C# instead. You have to learn something new either way; you may as well learn the one that’s easier.
(C# is easier because it catches, and clearly reports, a large number of errors that JS simply accepts and makes code that doesn’t work, such as when you mix up “=” and “==”.)
As for the error, I’m afraid I can’t see it either. Here’s what to do in such a case: comment out the entire guts of your Update method. Does it work now? If not, then the error is something else (probably you haven’t balanced your curly braces or some such.) If so, then uncomment just the local variable declarations in your Update method. Does it work now?
…And so on. Put your code back in, a few lines at a time, trying to make it syntactically correct at each stage. At some point, you’ll think it is correct, but the compiler will say “No way!”, and then you study the code you just put back, and find the problem.
@JoeStrout . I used javascript because the uploader teach it with that and also is there a difference in scripting languages? i don’t know that , i thought every scripting languages are same but never know that one is powerful than other . and the problem with me for scripting is it is not balanced , like i can able to design average looking looking 3D world but when it comes to scripting iam still a beginner , so it gives me a problem and @ blizzy i tried as you said and so got new errors sayingRAYCAST.js(18,50): BCE0019: ‘CanSwing’ is not a member of ‘RAIN.Motion.CharacterControllerMotor’. here is edited script
#pragma strict
var rayLength : int = 10;
private var treeScript : TreeController;
private var playerAnim : RAIN.Motion.CharacterControllerMotor;
function Update ()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Tree")
{
treeScript = GameObject.Find(hit.collider.gameObject.name). GetComponent (TreeController);
playerAnim = GameObject.Find("arms2"). GetComponent(RAIN.Motion.CharacterControllerMotor);
if(Input.GetButtonDown("Fire") && playerAnim.CanSwing == true)
{
treeScript.treeHealth -= 1;
}
}
}
}
What’s odd is that every bit of code in it is underlined. It’s not the code itself that’s odd, it’s the way it’s formatted in that post. I don’t even know how you managed it.
its ok . then i need to delete this script and also the tutor didnt use RAIN but i also did and it said in error did you mean RAIN and so i writ it like this. so we really need to use RayCast for tree cutting . all this script i write because i want tree to cut down when hit and spawn wood