Created
February 19, 2022 22:23
-
-
Save kazukitanaka0611/93f086862ad0a20601cf841ebf19def0 to your computer and use it in GitHub Desktop.
Shpereの大きさを変えながら縦横にならべるコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
public class Generate : MonoBehaviour | |
{ | |
[SerializeField] | |
private GameObject _spherePrefab = default; | |
[SerializeField] | |
private int _unitKazu = 16; | |
private List<GameObject> _sphereList = new List<GameObject>(); | |
private void Start() | |
{ | |
if (_spherePrefab != null) | |
{ | |
for (int i = 0; i < _unitKazu * _unitKazu; i++) | |
{ | |
float x = _spherePrefab.transform.localScale.x * (i / _unitKazu) + (_spherePrefab.transform.localScale.x / 2); | |
float y = _spherePrefab.transform.localScale.y * (i % _unitKazu) + (_spherePrefab.transform.localScale.y / 2); | |
GameObject sphere = Instantiate(_spherePrefab, new Vector3(x, y, _spherePrefab.transform.localPosition.z), Quaternion.identity); | |
float newScaleX = ((float)(i % (_unitKazu + 1)) / _unitKazu) * sphere.transform.localScale.x / 2; | |
float newScaleY = ((float)(i % (_unitKazu + 1)) / _unitKazu) * sphere.transform.localScale.y / 2; | |
float newScaleZ = ((float)(i % (_unitKazu + 1)) / _unitKazu) * sphere.transform.localScale.z / 2; | |
sphere.transform.localScale = new Vector3(newScaleX, newScaleY, newScaleZ); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment