Practice with Factory Design Pattern-Help Please?

Use code tags:

public class Factory : MonoBehaviour {
    public GameObject sphereButton;
    public GameObject cubeButton;
    public GameObject cylinderButton;

    public interface Shape
    {
        void Update();
    }
    public class Sphere: Shape
    {
        public GameObject sphere;


        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                sphere.GetComponent<MeshRenderer>().material.color = new Color(Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1));
                Destroy(sphere, 30.0f);
            }
        }
    }
    public class Cube : Shape
    {
        public GameObject cube;

        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Instantiate(cube);
                cube.GetComponent<MeshRenderer>().material.color = new Color(Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1));
                Destroy(cube, 30.0f);
            }
        }
    }
    public class Cylinder : Shape
    {
        public GameObject cylinder;

        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Instantiate(cylinder);
                cylinder.GetComponent<MeshRenderer>().material.color = new Color(Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1), Random.Range(0, 1));
                Destroy(cylinder, 30.0f);
            }
        }
    }

    public class ShapeFactory
    {
        public Shape GetShape(string shapeType)
        {
            if (shapeType == null)
            {
                return null;
            }
            if()
                return null;

        }
    }


}
1 Like