I have one cube in some point (x,y,z);
I would like to put Sphere -s into its nodes.
This script I connect with Cube.
public class HandsOnCube : MonoBehaviour
{
// Use this for initialization
private GameObject[] PNodes;
private Vector3[] pos;
private Vector3 offset;
private Quaternion offrot;
void Start ()
{
offrot = transform.rotation;
offset = transform.position - transform.localScale / 2;
pos = new[] {
new Vector3 (0f, 0f, 0f),
new Vector3 (0f, 0f, 1f),
new Vector3 (0f, 1f, 0f),
new Vector3 (0f, 1f, 1f),
new Vector3 (1f, 0f, 0f),
new Vector3 (1f, 0f, 1f),
new Vector3 (1f, 1f, 0f),
new Vector3 (1f, 1f, 1f)
};
int[] inds = new [] {0,1,2,3,4,5,6,7};
PNodes = new GameObject[8];
foreach (int i in inds) {
PNodes *= new GameObject ();*
_ PNodes = GameObject.CreatePrimitive (PrimitiveType.Sphere);_
PNodes .transform.position = pos + offset + offset_def;
_ PNodes .transform.localScale = new Vector3 (0.2f, 0.2f, 0.2f);_
_ //PNodes .transform.RotateAround = offrot;
RotateGameObjArround (PNodes , transform.position, offrot);
PNodes .SetActive (true);
* }*_
* }*
* void RotateGameObjArround (GameObject o, Vector3 aP, Quaternion Q)*
* { // ap - ArroundPoint*
* Vector3 angles = Q.eulerAngles;*
* o.transform.RotateAround (aP, new Vector3 (1f, 0, 0), angles.x);*
* o.transform.RotateAround (aP, new Vector3 (0, 1f, 0), angles.y);*
* o.transform.RotateAround (aP, new Vector3 (0, 0, 1f), angles.z);*
* }*
* // Update is called once per frame*
* void Update ()*
* {}*
}
Poblem: if Cube rotation = (10,20,30) then Spheres are not situated in right positions. I think that I have to modify RotateGameObjArround fn, but how? Any ideas?