Cas*_*und 5 c# unity-game-engine
我对Unity中的脚本非常陌生,我正在尝试创建一个按钮,一旦点击它就需要模拟按下的'F'键(拿起一个项目)
这是我目前的代码,在写这篇文章之前,我已经看过整个团结论坛,但找不到任何有用的东西.
码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class button : MonoBehaviour {
public void ButtonToClick(int clickToButton)
{
SendKeys.Send("F");
}
}
Run Code Online (Sandbox Code Playgroud)
MBS*_*MBS -2
从这个问题:
在http://inputsimulator.codeplex.com下载 zip 文件
使用 Unity 项目中的脚本 (C#) 将其解压到 Assets 目录
重新加载 MonoDevelop(如果已打开)
在顶部的脚本中写入:using WindowsInput;
在你的课堂上你可以使用它,例如:
InputSimulator.SimulateKeyPress (VirtualKeyCode.RIGHT); //模拟右箭头按下
编辑:
您可以使用 Nuget 安装它,无需上述链接:
Install-Package InputSimulator
Run Code Online (Sandbox Code Playgroud)
检查它在github上的存储库。