- Home /
Destroy Prefab with UI Slider
HI Guys,
I managed to create a simple tower in Unity. It is really basic. Each time the user click or touch the screen a new prefab is instantiated. I am trying to go forward with it and add ability to use sliders.
Say slider one will control height / number of floors being created. But don’t know how to use a slider to destroy GameObjects.
Basically you drag slider to the right and it creates prefabs, drag to the left and it destroys it.
Also how to control scale/translation/rotation of already instantiated prefabs in run time. I want be able to twist tower in run time with the slider.
I have attach two scripts I am currently using and link to a video.
Thank you
public class Instantiate : MonoBehaviour
{
public GameObject floorPlate;
public float floorHeight = 1f;
public float towerTwist = 1f;
public float slabHeight = 0.03f;
public float slabSize = 3f;
public float scale = 1f;
private float offset = 0f;
private float rotation = 0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetButtonUp("Fire1"))
{
GameObject floor;
floor = Instantiate(floorPlate, new Vector3(0f, offset, 0f), Quaternion.Euler(0f,rotation, 0f));
floorPlate.transform.localScale = new Vector3(slabSize, slabHeight, slabSize);
offset = floorHeight + offset;
rotation = rotation + towerTwist;
slabSize = slabSize / scale;
}
}
}
Comment
Answer by Artpen · Sep 19, 2019 at 12:29 PM
Here is a screenshot as well ...
screen-shot-2019-09-19-at-125022.png
(295.8 kB)