T-VIR-901_EpiLeARn/Assets/script/ReadMolecule.cs

36 lines
1016 B
C#
Raw Normal View History

2024-01-06 15:51:13 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ReadMolecule : MonoBehaviour
{
public TextAsset jsonFile;
void Start()
{
Molecules moleculesInJson = JsonUtility.FromJson<Molecules>(jsonFile.text);
2024-01-06 18:41:15 +01:00
int molNum = 0;
int dist = 5;
2024-01-06 15:51:13 +01:00
foreach (Molecule molecule in moleculesInJson.molecules){
2024-01-06 18:41:15 +01:00
GameObject moleculeObj = new GameObject(molecule.name);
foreach (Atom atom in molecule.atoms){
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
sphere.transform.parent = moleculeObj.transform;
sphere.name = atom.element;
sphere.transform.localPosition = new Vector3(atom.geometry[0], atom.geometry[1], atom.geometry[2]);
}
moleculeObj.transform.position = new Vector3(molNum*dist,0,0);
molNum++;
2024-01-06 15:51:13 +01:00
}
}
// Update is called once per frame
void Update()
{
}
}