- Home /
Rotate a spawned object whith onmousedrag and move it with onmousedown
Hello guys!!
I am a new unity programmer and i need some jelp. I am working to a project where i select a primitive mesh and spawn it to my scene. then sith a slider i can edit the spawned object scale and with another button i can change the object's color with random values. All good with that but i would like to be able to rotate the spawned object whith the onmousedrag and move it with the onmousedrop. Any ideas how can i manage something like that?
Thanks for your time here is my code so far:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class ChangeMeshFilter : MonoBehaviour { public Mesh[] myMesh= new Mesh[5]; private GameObject gObject; public Dropdown MeshSelector; private Slider scaleSlider; public float scaleMinValue; public float scaleMaxValue;
void Start ()
{
CreateObject();
MeshSelector.onValueChanged.AddListener(SelectMesh);
scaleSlider = GameObject.Find("ScaleManager").GetComponent<Slider>();
scaleSlider.maxValue = scaleMaxValue;
scaleSlider.minValue = scaleMinValue;
scaleSlider.onValueChanged.AddListener(ScaleSliderUdate);
}
void CreateObject()
{
gObject = new GameObject();
gObject.AddComponent<MeshFilter>().mesh = myMesh[0] ;
gObject.AddComponent<MeshRenderer>();
gObject.GetComponent<MeshRenderer>().material.color = Color.green;
}
private void SelectMesh(int index)
{
gObject.GetComponent<MeshFilter>().mesh = myMesh[index];
}
public void ColorChanger()
{
gObject.GetComponent<MeshRenderer>().material.color = Random.ColorHSV();
}
void ScaleSliderUdate (float value)
{
gObject.transform.localScale = new Vector3(value, value, value);
}
}