0
\$\begingroup\$

I'm building a UI system to edit selected 3D objects. I have spheres on the screen and I want to be able to edit their proprieties (radius for example). In order to do that I want the user to be able to click on a sphere and then it show a panel next to the object. When the user changes slider value the radius of the sphere which as been clicked on change. Using the new unity event system, I think it's easy to achieve, but I'm a new to unity and even if I know the basic I don't know how to organize this properly.

At the end my goal would be to select multiple sphere, right click and edit the radius to all selected spheres. http://imgur.com/WgBCrmk Any tips on how to do that ? Sorry for my poor english. Thanks

\$\endgroup\$
1
\$\begingroup\$

you should ray casts for selecting sphere game object, then use attached script to on value change in slider game object you can use this code

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class SelectSphere : MonoBehaviour {
public  GameObject selectedSphere;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        if(Input.GetMouseButtonDown(0))
        {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100)) 
            selectedSphere=hit.collider.gameObject;
        }
    }
    public void ChangeRadiusOfSphere()
    {
        if(selectedSphere!=null)
        {
            float sildervalue=GameObject.Find("Slider").GetComponent<Slider>().value;
            if(sildervalue!=0)
                selectedSphere.transform.localScale=new Vector3 (sildervalue*2f,sildervalue*2f,sildervalue*2f);
        }
    }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.