Hi mates,
I got a small C# snippet what i would like to convert to Js.
What is the script doing?
It instantiate for example 10 Cubes randomly around a sphere.
I started already to convert it to Java, but still got lots of errors. There must be no context menu, it could work also just on Start. Would be nice if someone is able to help me. I already was looking for converter tools.
Here the C#:
using UnityEngine;
using System.Collections.Generic;
public class PointsOnSphere : MonoBehaviour {
public GameObject prefab;
public int count = 10;
public float size = 20;
[ContextMenu("Create Points")]
void Create () {
var points = UniformPointsOnSphere(count, size);
for(var i=0; i<count; i++) {
var g = Instantiate(prefab, transform.position+points*, Quaternion.identity) as GameObject;*
g.transform.parent = transform;
}
}
Vector3[] UniformPointsOnSphere(float N, float scale) {
var points = new List();
var i = Mathf.PI * (3 - Mathf.Sqrt(5));
var o = 2 / N;
for(var k=0; k<N; k++) {
var y = k * o - 1 + (o / 2);
var r = Mathf.Sqrt(1 - y*y);
var phi = k * i;
points.Add(new Vector3(Mathf.Cos(phi)*r, y, Mathf.Sin(phi)*r) * scale);
}
return points.ToArray();
}
}
Here my Java so far.
var prefab : GameObject;
var count : int = 10;
var size : float = 20;
var points : Array;
function Start () {
var points = UniformPointsOnSphere(count, size);
for(var i=0; i<count; i++) {
var g = Instantiate(prefab, transform.position+points*, Quaternion.identity);*
g.transform.parent = transform;
}
}
function UniformPointsOnSphere ( N : float , scale : float ) : Vector3[] {
var points = new Array (Vector3(0, 0, 0));
_ var i = Mathf.PI * (3 - Mathf.Sqrt(5));_
var o = 2 / N;
for(var k=0; k<N; k++) {
var y = k * o - 1 + (o / 2);
var r = Mathf.Sqrt(1 - y*y);
var phi = k * i;
points.Add(new Vector3(Mathf.Cos(phi)*r, y, Mathf.Sin(phi)*r) * scale);
}
return points.Array;
}