random - C# randomly choosing from Vector3s -
this first time using c#. trying assign transform.position randomly either l1, l2, or l3. have made array of vector3s randomly take 1 of 3 vectors3 doesn't seem work. how prepare this? in advance. using monodevelop unity way.
l1=new vector3(x,y,z); l2=new vector3(y,x,z); l3=new vector3(z,x,y); random rand=new random(); vector3[] randomvector3=new vector3[]{l1,l2,l3}; transform.position=randomvector3[random.next(0,2)}; //error here
//note: work if utilize transform.position=l1 mentioned, want random.
in unity can utilize random.range
vector3[] randomvector3 = {l1,l2,l3}; transform.position = randomvector3[random.range(0, 3)];
you need utilize 0, 3
because function exclusive on sec parameter.
you clever , use:
random.range(0, randomvector3.length)
c# random vector unity3d
No comments:
Post a Comment