|
I have looked around to find an answer to my problem but have not come across any, so I'm sorry if I did overlook it. My script was working in the previous versions of Unity but ever since I did a recent update (I've been absent for a while) a lot of scripts have errors written all over them. Here is the script... The error is BCE0005: Unknown identifier: 'transform'. Located inside the shoot function, it's the line: instanceCannonball.rigidbody.AddForce (transform.forward * mechanics.force); I just don't see what's wrong with it. instanceCannonball was already declared and the variable used for adding force is declared in the class cannonballMechanics, referenced by mechanics... Anyway, I had the same problem earlier with the error, BCE0005: Unknown identifier: 'Instantiate', located inside the shoot function, the line: instanceCannonball = GameObject.Instantiate (cannon.cannonball, cannon.spawnPos.position, cannon.spawnPos.rotation); Prior to the update I did not have to put (GameObject.) in front of Instantiate, but I checked a recent post stating the devs changed the coding. Java is more strict on defining variables. Problem is. I dont know how to edit the (transform. forward) to fix the error. Any help or suggestions would greatly be appreciated. I'll still be attempting...
(comments are locked)
|
|
Sorry guys; I have figured out the issue. The code itself works but I received an error because the script bearing the code was named 'cannonBlast', which, is also, the name of a class inside the script. So I guess Unity tried to access the script--which is a class itself when using java--against the class inside of the script. I figured it out when arkon tried pasting my code into an empty js file; I did the same thing--obviously changing the script name--and it worked. Thanks a lot for your help on this one...
(comments are locked)
|
|
I've just pasted your code into an empty javascript file in my game and it all works fine with no errors. I suspect it's something to do with where you have the file inside your assets folder. I put it here and it all works fine. Game->Assets->Scripts
(comments are locked)
|

Briefly looking at your code I can't see an obvious reason for transform to be unavailable so I'll just explain what is happening when you use "transform". Using "transform" directly references the transform component on the object in which the script is attached. Try cacheing the transform in a variable then accessing it. var tr = gameObject.transform;