public class pickUpClick : MonoBehaviour {
 //public GameObject SpawnPoint;
 public enum Item
 {
  Flashlight,
 }
 public float Distance = 5.0f;
 
 public Item item;
 void OnMouseDown()
 {
  var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
  if (Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance) 
  {
   HUD.HasFlashlight = true;
   Destroy (gameObject);
   HUD.PickUpTextTorch = "";
  
   
   //Instantiate(Resources.Load("Flashlight"));//, gameObject.transform.position = playerPos);
   //gameObject.transform.position = playerPos;
   //SpawnPoint = (GameObject)Instantiate(Resources.Load("Flashlight"));
  }
 }
 void Update()
 {
  var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
  if (Vector3.Distance (playerPos, transform.position) <= Distance )// && HUD.HasFlashlight == false
  {
   HUD.PickUpTextTorch = "Left Click To Pick Up Flashlight";
  }
  else
  {
   HUD.PickUpTextTorch = "";
  }
 }
// public AudioClip flashlightSound;
// public AudioClip batterySound;
// 
// void OnMouseDown()
// {
//  var playerPos = GameObject.FindGameObjectWithTag("Player").transform.position;
//  
//  if(Input.GetMouseButtonDown(0) && Vector3.Distance(playerPos, transform.position) <= Distance)
//  {
//   if(item == Item.Flashlight)
//   {
//    Flashlight.HeadLightMount.SetActiveRecursively(true);
//    Flashlight.HeadLightMount.active = true;
//    
//    AudioSource.PlayClipAtPoint(flashlightSound, transform.position, 1);
//    
//    HUD.HasFlashlight = true;
//   }
//   else
//    HUD.BatteryCount++;
//   
//   AudioSource.PlayClipAtPoint(batterySound, transform.position, 1);
//   
//   Destroy(gameObject);
//  }
// }
}
 
No comments:
Post a Comment