How to return multiple time at the same time

Hello guys,
So I want to expose my function to another script, and I want to expose a function that has return multiple values.I want to know how to send that value to another script at the same time?

Public int sendTriggerStatus()
{
//return trigger1,trigger2,trigger3;
}

Let’s solve one problem after another. First, if you only want to return a bunch of objects of the same type, you can use an array or a list to bundle them and then return the array or list. It is not possible to return more than one object or value in .net at the same time.

The code to return three triggers at the same time may look as follows:

public int SendTriggerStatus()
{
    Collider[] triggers = new Collider[3] {trigger1, trigger2, trigger3};
    return triggers;
}

Also if not everything is the same data type you could also create a struct and fill it with data and return that.

I want to send bool variable to other script, so i want to access the function sendTriggerStatus variables,trigger1,trigger2,and trigger3 in other script,if the variables are true then ill setactive the other gameobjects based on trigger status

Public int sendTriggerStatus()
{
//return trigger1,trigger2,trigger3;(trigger1,2,and 3 are bvariables with bool type;
}

anyway im using c#

I think I am starting to understand what your are looking for. It seems more suitable to me to split your functionality up into two different functions. The first one to calculate the trigger status:

public bool TriggerStatus()
{
    return trigger1 && trigger2 && trigger3;
}

And the second one to activate the other game object. In this code, it is supposed to be in the same script as TriggerStatus, however, this could be changed.

public void SetGameObjectActivity ()
{
    bool status = TriggerStatus ();
    theOtherGameObject.SetActive (status);
}

so this is my codes, actually in CheckTrigger code,I want to make a function that can pass information about trigger1,trigger2,and trigger3 values,and I want to access my trigger1,trigger2,and trigger3 variables in ActiveTheObjects code, but I don’t want to make 3 functions to return 3 values,I only want to make 1 function that pass information about each variables.I know that we can separate each of variables into a function that return each value(so there are 3 function if we want to separate the variables and I think it’s quite waste to separate each variables in different function)…so how to do this?

2053658–133605–ActiveTheObjects.cs (442 Bytes)
2053658–133606–CheckTrigger.cs (478 Bytes)

If you want to access trigger1, trigger2 and trigger3, you can simply make the variable public.

using UnityEngine;
using System.Collections;

public class CheckTrigger : MonoBehaviour
{
   public bool trigger1, trigger2, trigger3 = false;

   void OnTriggerEnter(Collider other)
   {
     Debug.Log ("Trigger Activated");

     if (other.gameObject.tag == "Trigger_Point1")
     {
       trigger1 = true;
     }
   }

   public bool TriggerStatus()
   {
     return trigger1 && trigger2 && trigger3;
   }
}
using UnityEngine;
using System.Collections;

public class ActiveTheObjects : MonoBehaviour {

   private CheckTrigger setGameObjStatus;

   void Start ()
   {
     GameObject GetTriggerStat = GameObject.FindWithTag ("Player");
     if (GetTriggerStat != null)
     {
       setGameObjStatus=GetTriggerStat.GetComponent<CheckTrigger>();
     }
   }
   
   void Update ()
   {
     Debug.Log (setGameObjStatus.trigger1);
     Debug.Log (setGameObjStatus.trigger2);
     Debug.Log (setGameObjStatus.trigger3);
     Debug.Log (setGameObjStatus.TriggerStatus ());
   }
}

Thanks Dude :smile: