using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickupScript : MonoBehaviour
{
    public GameObject pickupParticles;
    public AudioClip pickupSound, throwSound;
    [Range(1f,100f)] public float bonus;
    // Start is called before the first frame update
    void Start()
    {
        if (throwSound) AudioSource.PlayClipAtPoint(throwSound, Camera.main.transform.position);
        GetComponent<Rigidbody>().AddForce((1f*Vector3.forward*Random.value + 7f*Vector3.forward) + 7f* Vector3.up,ForceMode.VelocityChange);
    }


    void OnTriggerEnter(Collider objetTouche)
    {
        if (objetTouche.tag == "Player")
        {
            objetTouche.SendMessage("AddScore", bonus, SendMessageOptions.DontRequireReceiver);
            if (pickupParticles) Instantiate(pickupParticles, transform.position, Quaternion.identity);
            if (pickupSound) AudioSource.PlayClipAtPoint(pickupSound, Camera.main.transform.position);
            Destroy(gameObject);
        }
    }
}
