1.效果实现视频
CreateTrapezoidalBlock
2.实现代码
CubeGenerate类:
1.实现对Button控件,Slider控件,Input Field控件的监听,并处理触发之后的改变
2.在任意位置生成几何物体,删除所有几何物体
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CubeGenerate : MonoBehaviour
{
public Button BtnGenerate;
public Button BtnReset;
public InputField BottomwidthInputField;
public InputField TopwidthInputField;
public InputField HighInputField;
public Slider BottomwidthSlider;
public Slider TopwidthSlider;
public Slider HeightSlider;
public Material targetMaterial;
public float bottomWidth = 1f;
public float topWidth = 1f;
public float height = 1f;
private Transform Parent;
private void Awake()
{
Parent = GameObject.Find("Parent")?.transform;
BottomwidthInputField.text = bottomWidth.ToString();
TopwidthInputField.text = topWidth.ToString();
HighInputField.text = height.ToString();
UpdateInputFields();
}
private void Start()
{
BtnGenerate.onClick.AddListener(GenerateCube);
BtnReset.onClick.AddListener(ClearCubes);
BottomwidthSlider.onValueChanged.AddListener(OnBottomWidthChanged);
TopwidthSlider.onValueChanged.AddListener(OnTopWidthChanged);
HeightSlider.onValueChanged.AddListener(OnHeightChanged);
BottomwidthInputField.onEndEdit.AddListener(OnBottomWidthEndEdit);
TopwidthInputField.onEndEdit.AddListener(OnTopWidthEndEdit);
HighInputField.onEndEdit.AddListener(OnHeightEndEdit);
}
private void Update()
{
Debug.Log(BottomwidthInputField.text);
if (float.TryParse(BottomwidthInputField.text, out float bw))
{