Skip to main content
Fix typos, formatting
Source Link
Kevin
  • 7k
  • 1
  • 12
  • 32

As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script:

Script on the unit:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable;available; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliableSetAvailable(bool state)
   { avaliableavailable = state; }

   public bool GetAvaliableGetAvailable()
   { return avaliable;available; }

}

 
Your Code:

Your Code:

public static class CharacterChange
{
   public static GameObject PickedUnit;
   public static void SelectUnit(GameObject[] units) // call this function with array input
   { 
     
        foreach(GameObject unit in units) 
        {
            if (unit.GetComponent<UnitCode>().GetAvaliableGetAvailable() == true)
            {  
                // you can make local variable and save the progress here, for example
                // PickedUnit = unit;
                // return; // return the wanted unit
            }
       }
   }
}

AttackAttach the UnitScript to the units you wanna select/interact with.

As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}

 
Your Code:

public static class CharacterChange
{
   public static GameObject PickedUnit;
   public static void SelectUnit(GameObject[] units) // call this function with array input
   { 
     
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
        {  
        // you can make local variable and save the progress here, for example
        // PickedUnit = unit;
        // return; // return the wanted unit
        }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script:

Script on the unit:

public class UnitScript
{
   [SerializeField] private bool available; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvailable(bool state) { available = state; }

   public bool GetAvailable() { return available; }

}

Your Code:

public static class CharacterChange
{
   public static GameObject PickedUnit;
   public static void SelectUnit(GameObject[] units) // call this function with array input
   { 
     
        foreach(GameObject unit in units) 
        {
            if (unit.GetComponent<UnitCode>().GetAvailable() == true)
            {  
                // you can make local variable and save the progress here, for example
                // PickedUnit = unit;
                // return; // return the wanted unit
            }
       }
   }
}

Attach the UnitScript to the units you wanna select/interact with.

added 20 characters in body
Source Link

As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script.:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public static class CharacterChange
{
   [SerializeField]public GameObject[]static units;GameObject //PickedUnit;
 put all thepublic object'sstatic thatvoid youSelectUnit(GameObject[] wantunits) to// interactcall withthis (withfunction thewith UnitScript)array here
input
   public void{ SelectUnit()
   {  
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
        {  
        // codeyou tocan selectmake thislocal unitvariable and save the progress here, for example
        // PickedUnit = unit;
        // return; // return the wanted unit
        }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

.. or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.

As far as I understand you want to select first avaliable character of some array. If that's the case, you can try the following script.

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public class CharacterChange
{
   [SerializeField] GameObject[] units; // put all the object's that you want to interact with (with the UnitScript) here

   public void SelectUnit()
   {
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
     { 
       // code to select this unit
     return;
     }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

.. or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.

As far as I understand you want to select first avaliable character of some array through static script that will save the picked unit. If that's the case, you can try the following script:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public static class CharacterChange
{
   public static GameObject PickedUnit;
   public static void SelectUnit(GameObject[] units) // call this function with array input
   { 
     
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
        {  
        // you can make local variable and save the progress here, for example
        // PickedUnit = unit;
        // return; // return the wanted unit
        }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

added 41 characters in body
Source Link

As far as I understand you want to select first avaliable character of some array. If that's the case, either attackyou can try the following script on the unit and check if it's avaliable:.

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public class CharacterChange
{
   [SerializeField] GameObject[] units; // put all the object's that you want to interact with (with the UnitScript) here

   public void SelectUnit()
   {
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
     { 
       // code to select this unit
     return;
     }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

.. or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.

As far as I understand you want to select first avaliable character of some array. If that's the case, either attack the script on the unit and check if it's avaliable:

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public class CharacterChange
{
   [SerializeField] GameObject[] units; // put all the object's that you want to interact with (with the UnitScript) here

   public void SelectUnit()
   {
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
     { 
       // code to select this unit
     return;
     }
   }
}

or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.

As far as I understand you want to select first avaliable character of some array. If that's the case, you can try the following script.

Script on the unit:
public class UnitScript
{
   [SerializeField] private bool avaliable; // use this type of writting if you want easy access on the editor, and at the same time protection in the code
   public void SetAvaliable(bool state)
   { avaliable = state; }

   public bool GetAvaliable()
   { return avaliable; }

}


Your Code:

public class CharacterChange
{
   [SerializeField] GameObject[] units; // put all the object's that you want to interact with (with the UnitScript) here

   public void SelectUnit()
   {
     foreach(GameObject unit in units)
     { if(unit.GetComponent<UnitCode>().GetAvaliable() == true)
     { 
       // code to select this unit
     return;
     }
   }
}

Attack the UnitScript to the units you wanna select/interact with.

.. or just make array of booleans and go through each through for loop and choose the unit with the same [i], but that's not so suggested way.

deleted 2 characters in body
Source Link
Loading
added 116 characters in body
Source Link
Loading
Source Link
Loading