I've a GameObjectManager (`GuardarObjetos`) that is instantiate when the code run and I've GameObjects (Cubes prefabs) that is instantiate on runtime when the `AddButton` is clicked that contains `Spawner.Spawn()`
The idea is to use the `GuardarObjetos` to do a copy of the object selected. Then I can to paint, to delete and to change name of the Cube, for example.
Repository: https://github.com/emicalvacho/MapaMentalAR
I have already tried to do `Debug.Log("BEFORE SET OBJECT "+ o.name)` and `Debug.Log("AFTER SET OBJECT "+ o.name)` in the script `ObjetosSeleccionados` to check the selected object is saved correctly and That's right!
The next code is into `Object.Cube #` and receive `ObjetosSeleccionados` as Script
public class SelectScript : MonoBehaviour
{
public GameObject obj;
private GameObject findObj;
public ObjetosSeleccionados script;
private bool band = true;
public void OnMouseDown()
{
script.setObjSelec(obj);
findObj = FindInactiveObject("CanvasManager");
if(findObj != null){
if(band){
findObj.SetActive(true);
band = false;
}
else{
findObj.SetActive(false);
band = true;
}
Debug.Log(obj.name);
}
}
private GameObject FindInactiveObject(string findObj){
GameObject[] objs = Resources.FindObjectsOfTypeAll();
foreach(GameObject o in objs){
if(o.name == findObj){
return o;
}
}
Debug.Log("EL OBJECTO A BUSCAR NO EXISTE");
return null;
}
}
This code is into `Object.Cube #`
public class ObjetosSeleccionados : MonoBehaviour
{
private GameObject objSelect;
public void setObjSelec(GameObject o){
objSelect = o;
Debug.Log("Objeto seteado: "+ objSelect.name);
}
public GameObject getObjSelect(){
return objSelect;
}
}
This code is into `Spawner` GameObject and `Spawner` receive the script `ObjetosSeleccionados`
public class ButtonsEventsScript : MonoBehaviour
{
public ObjetosSeleccionados script;
private GameObject obj;
void Update()
{
obj = script.getObjSelect();
}
public void ComunicarCambioColor(){
Renderer rend = obj.GetComponent();
rend.material.color = Random.ColorHSV();
}
public void EliminarObjeto(){
Destroy(obj);
}
}
But this isn't work. Any idea?
↧