GUI Input C#

on an update function in C#, how would I convert this from saying "If Input.GetButton(“fire1”) to doing the same thing but for mobile gui? Pretty much, this only works for the PC by clicking the mouse button, but im asking how do I make it to where it does the same thing but by clicking on a GUI button? heres the code:

if(Input.GetButton("Fire1")) {
    // Player wants to shoot...so. Shoot.
netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
        }

well using the old gui you can achieve this by taking the line and adding it to OnGUI() as show below :

void OnGUI()
{
   if  (GUILayout.Button("Test"))
   {
      netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
   }
}

but for your needs (mobile ui) I would suggest making the button using the new unity ui and simply have the button call the FireWeapon function :

public void FireWeapon()
{
   netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
}
1 Like

thanks, now I wondering if this could be done with the update function, no?

there is no need to run this in the update function

Oh ok thanks (:

no problem :slight_smile: