创建一个空物体,然后将下面代码挂在上就行了:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Creratsphere : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);//type还有好几种
sphere.transform.position = new Vector3(-0.5f, 0.5f, 1);
sphere.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
sphere.name = "one";
}
// Update is called once per frame
void Update()
{
}
}