- Home /
How to execute functions from a GameObject Manager from a script to another Object?
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<GameObject>();
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<Renderer>();
rend.material.color = Random.ColorHSV();
}
public void EliminarObjeto(){
Destroy(obj);
}
}
But this isn't work. Any idea?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[Augmented reality] Change object in different Coordinates system? 1 Answer
how can I use the vuforia text recogniton with out using the sample package? 0 Answers
How to create an application with "tracking objects without markers"? 0 Answers