Hey guys, I’m so confused on how to do this… This is a pickup object code for keyboard. I want to convert my Input.GetButtonUp(“Use”) to a GUI button that when you tap on the GUI button the character will pickup the object… Thanks for the Replies in Advance …
Here’s the code:
#pragma strict
var Primary : Item; //Your Primary item holder
var Secondary : Item; //Your Secondary item holder
var myLayerMask : LayerMask;
var p : GUITexture;
private var HitItem : GameObject; //Item that raycast hits.
function Awake() {
p = GameObject.Find(“pick”).guiTexture;
}
function Update ()
{
for (var touch : Touch in Input.touches)
{
if(touch.phase == TouchPhase.Stationary p.HitTest(touch.position)){
if(Input.GetButtonUp(“Use”)) //Remember to make new Input called “Use”
{
var hit: RaycastHit;
var Direction = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, Direction * 2.5, Color.blue); //Shows raycast when you press “Use”
if(Physics.Raycast(transform.position, Direction, hit, 2.5, myLayerMask))
{
if(hit.transform.tag == “Item”) //If raycast hits transform.tag “Item”.
{
HitItem = hit.transform.gameObject; //HitItem becomes hit.gameObject.
var ItemScr : ItemScript = HitItem.GetComponent(“ItemScript”);
if(ItemScr.MyItem.IsSecondary) //If Hit item is Secondary
{
if(Secondary.ActiveObj == null) //Checks if you dont have Secondary Item
{
Secondary = ItemScr.MyItem;
Destroy(hit.transform.gameObject);
if(Primary.ActiveObj == null) //Checks if you have already
{ //equipped item in your hand.
Secondary.ActiveObj.active = true;
}
else if(Primary.ActiveObj)
{
if(Primary.ActiveObj.active == false)
{
Secondary.ActiveObj.active = true;
}
}
}
}
//And same to primary
if(!ItemScr.MyItem.IsSecondary) //If Hit item is Primary
{
if(Primary.ActiveObj == null) //If you don’t have primary, goes on…
{
Primary = ItemScr.MyItem;
Destroy(hit.transform.gameObject);
if(Secondary.ActiveObj == null)
{
Primary.ActiveObj.active = true;
}
else if(Secondary.ActiveObj)
{
if(Secondary.ActiveObj.active == false)
{
Primary.ActiveObj.active = true;
}
}
}
}
}
}
}
}
}
}