Javascript Unity 3d库存脚本(在拾取对象后,再次表示拾取压力)
我正在为对象创建一个清单,当我拾取对象时,它存储在清单中,但我的显示行(按E键拾取)仍然显示。 方法ONGUI,我觉得出了点问题, 这是FPS皮卡的代码Javascript Unity 3d库存脚本(在拾取对象后,再次表示拾取压力),javascript,unity3d,scripting,inventory,Javascript,Unity3d,Scripting,Inventory,我正在为对象创建一个清单,当我拾取对象时,它存储在清单中,但我的显示行(按E键拾取)仍然显示。 方法ONGUI,我觉得出了点问题, 这是FPS皮卡的代码 #pragma strict var InstructionBoxSkin : GUISkin; var ButtonToPress : KeyCode = KeyCode.E; var PickUpDistance = 1.7f; private var canPickUp = false; private var theItem : I
#pragma strict
var InstructionBoxSkin : GUISkin;
var ButtonToPress : KeyCode = KeyCode.E;
var PickUpDistance = 1.7f;
private var canPickUp = false;
private var theItem : Item;
private var thePlayer : Transform;
private var dist = 9999f;
@script AddComponentMenu ("Inventory/Items/First Person Pick Up")
@script RequireComponent(Item)
function Awake ()
{
theItem = (GetComponent(Item));
if (InstructionBoxSkin == null)
{
InstructionBoxSkin = Resources.Load("OtherSkin", GUISkin);
}
}
function RetrievePlayer (theInv : Inventory)
{
thePlayer = theInv.transform.parent;
}
function OnGUI ()
{
//This is where we draw a box telling the Player how to pick up the item.
//
GUI.skin = InstructionBoxSkin;
GUI.color = Color(1, 1, 1, 0.7);
if (canPickUp == true)
{
if (transform.name.Length <= 1)
{
GUI.Box (Rect (Screen.width*0.5-(165*0.5), 200, 165, 22), "Press E to pick up " + transform.name + ".");
}
else
{
GUI.Box (Rect (Screen.width*0.5-(185*0.5), 200, 185, 22), "Press E to pick up " + transform.name + ".");
}
}
}
function Update ()
{
if (thePlayer != null)
{
dist = Vector3.Distance(thePlayer.position, transform.position);
if (dist <= PickUpDistance)
{
canPickUp = true;
}
else
{
canPickUp = false;
}
//This is where we allow the player to press the ButtonToPress to pick up the item.
if (Input.GetKeyDown(ButtonToPress) && canPickUp == true)
{
theItem.PickUpItem();
}
}
}
function OnDrawGizmosSelected ()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere (transform.position, PickUpDistance);
}
#pragma strict
var指令boxskin:GUISkin;
var按钮按下:KeyCode=KeyCode.E;
var拾取距离=1.7f;
私有var=false;
私人项目:项目;
私有层:转换;
专用var dist=9999f;
@脚本添加组件菜单(“库存/物品/第一人称提货”)
@脚本要求重新组件(项目)
函数唤醒()
{
ITEEM=(获取组件(项目));
如果(指令BoxSkin==null)
{
说明boxskin=Resources.Load(“OtherSkin”,GUISkin);
}
}
函数检索播放器(INV:目录)
{
thePlayer=theInv.transform.parent;
}
函数OnGUI()
{
//在这里,我们画一个方框,告诉玩家如何拾取物品。
//
GUI.skin=说明BoxSkin;
GUI.color=color(1,1,1,0.7);
如果(CanPick==真)
{
如果(transform.name.Length看起来CanPick从未设置为false
是否改变:
if (Input.GetKeyDown(ButtonToPress) && canPickUp == true)
{
theItem.PickUpItem();
canPickUp = false;
}
解决问题?我试图将其设置为false,但随后它就不起作用了@Kaos_nyrb