Saturday, 22 March 2014

Battery pick up

public class HouseBatteryPickUp : MonoBehaviour {

public float Distance = 5.0f;

public GameObject Battery;

// void OnTriggerEnter(Collider other)
// {
// if (other.tag == "Player") { //&& Input.GetButtonDown("xButton") == true)
// HUD.HasFlashlight = true;
// Destroy (gameObject);
// }
//
//
// }
void OnMouseDown()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
{
HUD.BatteryCount++;
Destroy(gameObject);
HUD.PickUpTextBattery = "";
}
}


void Update()
{
var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;

if (Vector3.Distance (playerPos, transform.position) <= Distance)
{
HUD.PickUpTextBattery = "Left Click To Pick Up Battery";
}

else
{
HUD.PickUpTextBattery = "";
}

}
}

No comments:

Post a Comment