Answer the question
In order to leave comments, you need to log in
How to pass an object of any class to a method?
I have a method in each prefab with its own class that passes a click on it to the main class
public class Test1 : MonoBehaviour, IPointerClickHandler{
public void OnPointerClick(PointerEventData pointerEventData){ GameController.instance.CellClick(this); }
.....
public class Test2 : MonoBehaviour, IPointerClickHandler{
public void OnPointerClick(PointerEventData pointerEventData){ GameController.instance.CellClick(this); }
......
public class GameController : MonoBehaviour{
public void CellClick(......){
Answer the question
In order to leave comments, you need to log in
Well vrodeby all same prefabs are inherited from GameObject'a?
Can it be like this
public void CellClick(GameObject o){
if(o.GetType() == typeof(Car)){
Car car = (Car)o ;
//todo
}
if(o.GetType() == typeof(Animal)){
Animal animal= (Animal)o ;
//todo
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question