|
// -- Amended Question -- I have successfully rewritten a Third Person Controller tutorial on 3D Buzz from C# to JavaScript, with one major exception. Where the C# script creates an 'Instance' to read and write vars from , I found the other scripts and stored them in local vars. This is going to give me future problems so I would like to finally find out : How do I create an 'Instance' in JavaScript for my other scripts to reference ? C# example : My js workaround : Any help or info would be greatly appreciated. // Thanks , Jay. // // ---- First Posted Question ---- I am following the Third Person Controller videos on 3D Buzz, but they are written in C#. My goal is to follow the video's and write the code in JavaScript. From what I understand that I am trying to do, is establish a set of vars to live in a 'class' , then I should create an instance of this class, for other scripts to access vars or adjust vars. In my previous projects, to read/edit other scripts' data I have simply assigned a e.g. var myTPC : ScriptTPC; and used GetComponent in the Start to load the script. So before I start; can someone please help me understand what is being set up in this C# script : and how can I edit my converted javascript to use class and assign Instance : Many thanks, I am self-taught so alot of the terminology is lost on me. 3D Buzz link : http://www.3dbuzz.com/vbforum/content.php?212 Scroll down to -> Section 2 ; Video 6 - TP_Controller Skeleton Edit 1 : I understand I have to load CharacterController , and this actually loads preset functions I can call on (TransformDirection , Move, IsGrounded etc) , I don't understand how to create an 'Instance' that all scripts can call on. My method would be to load the other scripts into a var then edit e.g. var myTPC : ScriptTPC; myTPC.posX = 1; (would change the posX var on ScriptTPC to 1). Can I just do this instead of creating an Instance? Edit 2 : So far my scripts are working , using a different method of reading and writing to each other. Although I do get a Warning : BCW0028: WARNING: Implicit downcast : and I'll have to do the same for the TP_Camera script
(comments are locked)
|
|
Answered on this Question : http://answers.unity3d.com/questions/235417/how-do-i-create-a-static-instance-in-javascript.html
(comments are locked)
|
Thanks for taking the time to show what the C# is doing. I should have explained better that I want to make the static (only one) Instance using JavaScript. So far my scripts are working , using a different method of reading and writing to each other : and I'll have to do the same for the TP_Camera script
Apr 04 '12 at 09:30 AM
alucardj
(comments are locked)
|

... and a post-question : what is the difference between a public and static var ? (I've only used public and private (and hide in inspector public)).
http://answers.unity3d.com/questions/53538/public-private-and-static-variables-in-js.html
Thanks, that helped clear up static vars. Still leaves me with how to create an Instance in JavaScript (which I now see static would make sure there is only one of these Instance's in existance).