Trigger a command from Unity



  • This is an example script you can put on any object in Unity, so now you can trigger commands in the games you build.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Networking;
    
    public class scr : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            
        }
    
        // Update is called once per frame
        void Update()
        {
            if (Input.anyKeyDown)
            {
                Debug.Log("A key or mouse click has been detected");
    
                var trigger = "calculator";
                var computer = "laptop";
                var parameters = "";
                var token = "(your token)";
                StartCoroutine(TriggerCMD(trigger, computer, parameters, token));
            }
        }
    
        IEnumerator TriggerCMD(string trigger,string computer,string parameters, string token)
        {
            UnityWebRequest www = UnityWebRequest.Get("https://www.triggercmd.com/api/run/triggerSave?trigger=" + trigger + "&computer=" + computer + "&params=" + parameters + "&token=" + token);
            yield return www.SendWebRequest();
    
            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                // Show results as text
                Debug.Log(www.downloadHandler.text);
    
                // Or retrieve results as binary data
                byte[] results = www.downloadHandler.data;
            }
        }
    }
    

Log in to reply