Javascript to C#: Vector 3 rigidbody

Hi… trying to convert a JS file to C#. I’m having issues with the rigidbody.velocity = Vector3… here’s the code in JS:

function Start () {
rigidbody.velocity = Vector3(Random.Range(-2,2),Random.Range(3,5),0);

in conversion, I get the error, “Assets/Scripts/heartdrop.cs(8,38): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected” But I don’t understand this! thanks!

For C# you need the ‘new’ keyword in front of the ‘Vector3’. Also note your Random.Range() call is using the integer version of Random.Range(). The integer version is exclusive of the final value, and will only return integers. So Random.Range(-2, 2) will only return the values -2, -1, 0, and 1. I’m guessing you want the float version. So putting the two together:

rigidbody.velocity = new Vector3(Random.Range(-2.0,2.0),Random.Range(3.0,5.0),0.0);