Saturday, 22 March 2014

Collectable (same for all collectables with different variable names)

public class Collectable2 : MonoBehaviour {

public GameObject Collectable;

public float Distance = 5.0f;

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

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

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

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

else
{
HUD.PickUpTextCollectable2 = "";
}

}

}

No comments:

Post a Comment