|
What is the syntax for creating a function in javascript which can modify the value of a given parameter ? For example, the unity function Vector3.Smoothdamp modifies "currentVelocity" The function signature is (from Unity scripting manual): static function SmoothDamp (current : Vector3, target : Vector3, ref currentVelocity : Vector3, smoothTime : float, maxSpeed : float = Mathf.Infinity, deltaTime : float = Time.deltaTime) : Vector3 The function uses the "ref" keyword to (apparently) indicate what looks like C-style indirection (i.e., *currentVelocity). The "ref" keyword is also a feature of C# (as well as "out"), which produces the same effect in C#. However, when I try to write a javascript function using "ref" in the same manner as shown in the unity docs, I get an error: BCE0043: "unexpected token: currentVelocity"
(comments are locked)
|
|
You can't specify out or ref variables in functions when using Javascript. You can make use of functions that have ref or out variables that are written in C#, but can't declare them in Javascript. (I hope they add this sometime...it's the one thing about Javascript that I really don't like, and obviously the functionality is already there, so it shouldn't take much to implement it properly.) Ok ... thanks for the answers re: Unity v 3.4.2f2
Feb 08 '12 at 01:12 PM
r210
(comments are locked)
|

You shouldn't have to use the ref keyword in Unity Script, just pass in the parameter that references it and that should be it.