paintinx

create sphere // perftest

Apr 8th, 2021
446
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6. public class Create_Sphere_3 : MonoBehaviour
  7. {
  8.     // build a sphere and Set is as prefab - than set it into the game obj / thx to bensen!
  9.     public GameObject prefab;
  10.     // how much spheres ...
  11.     public int amount;
  12.     // how far is the area ...
  13.     public int space = 1;
  14.     // start position
  15.     Vector3 position;
  16.  
  17.  
  18.     // Start is called before the first frame update
  19.     void Start()
  20.     {
  21.         // plane building
  22.         GameObject plane = GameObject.CreatePrimitive(PrimitiveType.Plane);
  23.         plane.transform.position = new Vector3(0, -5, 0);
  24.         plane.transform.localScale = new Vector3(5, 1, 5);
  25.         //new Vector3 ( Random.Range (-0.1f, 0.1f), Random.Range (-0.1f, 0.1f), 0);
  26.  
  27.         //ori: position = new Vector3(-5f, 10f, -4f);
  28.         position = new Vector3(0, 0, 0); //position 1st sphere
  29.         // function here
  30.         CreatePrefabSpheres(amount * 2);
  31.         // CreatePrimitiveSpheres(amount * space);
  32.     }
  33.  
  34.  
  35.     // 3 times prefab instantiating
  36.     private void CreatePrefabSpheres(int amount)
  37.     {
  38.         for (int a = 0; a < amount; a += space)
  39.         {
  40.             for (int b = 0; b < amount; b += space)
  41.             {
  42.                 for (int c = 0; c < amount; c += space)
  43.                 {
  44.                     GameObject sphere = Instantiate(prefab, new Vector3(position.x + a, position.y + b, position.z + c), Quaternion.identity);
  45.                     sphere.AddComponent<Rigidbody>();
  46.                 }
  47.             }
  48.         }
  49.     }
  50.  
  51.     // 3 times prefab instantiating
  52.     private void CreatePrimitiveSpheres(int amount)
  53.     {
  54.         for (int a = 0; a < amount; a += space)
  55.         {
  56.             for (int b = 0; b < amount; b += space)
  57.             {
  58.                 for (int c = 0; c < amount; c += space)
  59.                 {
  60.                     GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
  61.                     sphere.transform.position = new Vector3(position.x + a, position.y + b, position.z + c);
  62.                     // sphere.AddComponent<Rigidbody>();
  63.                     // without gravity
  64.                     sphere.GetComponent<Rigidbody>().useGravity = false;
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×