HOW TO.. Grouping gameobject and move object in arraylist (Runtime)
Right now I'm try to grouping the instantiate dynamic object in runtime, But i don't sure how to do step that I think is
select the multiobject, which I use array to store all the selected item.
public List<GameObject> selectedUnits = new List<GameObject>() ;
click the buttonUI to group all of selected object (Which I can move it all at once)
so if its possible to move all the object in arraylist at once by clickanddrag? and how can I group or combine the multiselected gameobject in runtime ?
thanks, sorry for my beginner skill.
Can you show some code and explain exactly what are you trying to achieve?
Ok, at first I want to get selected object by mouse click and deselect it by clicking outside the object
using UnityEngine;
using System.Collections;
public class $$anonymous$$ouse$$anonymous$$anager : $$anonymous$$onoBehaviour {
public GameObject selectedObject;
public List<GameObject> selectedUnits = new List<GameObject>() ;
void Start () {
}
// Update is called once per frame
void Update () {
Ray ray = Camera.main.ScreenPointToRay( Input.mousePosition );
RaycastHit hitInfo;
if( Physics.Raycast( ray, out hitInfo ) ) {
GameObject hitObject = hitInfo.transform.root.gameObject;
SelectObject(hitObject);
}
else {
ClearSelection();
}
}
void SelectObject(GameObject obj) {
if(selectedObject != null) {
if(obj == selectedObject)
return;
ClearSelection();
}
selectedObject = obj;
}
}
void ClearSelection() {
if(selectedObject == null)
return;
}
selectedObject = null;
}
}
and right now I can selected and deselected object but I want to select multi object by click +shift toward the object and add it in to array, and I want to manipulate those multi object that have been selected to move according to mousePosition while dragging, Any suggestion for this idea?