I would like to take WeaponID etc. values from this script:
public class WeaponInfo : MonoBehaviour
{
public string WeaponName;
public float WeaponID;
public float Ammo;
public float FireRate;
public float Damage;
}
Into the Pickup script:
public class Pickup : MonoBehaviour
{
[SerializeField]
private bool pickUpAllowed;
// Use this for initialization
private void Start()
{
gameObject.SetActive(true);
}
// Update is called once per frame
private void Update()
{
if (pickUpAllowed && Input.GetKeyDown(KeyCode.E))
PickUp();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("body"))
{
gameObject.SetActive(true);
pickUpAllowed = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("body") && Input.GetKeyDown(KeyCode.E))
{
gameObject.SetActive(false);
pickUpAllowed = false;
}
}
private void PickUp()
{
Destroy(gameObject);
Debug.Log("Player Picked up:");
}
}
that is attached to the same Weapon object. The plan is that I want to make the WeaponPickup Script take Information from the WeaponInfo script, so I could use it when my Character picks it up it would take the information of what is the weapon ID etc. So if the character picks up a weapon with 10 ammunition it would change the character WeaponID from hands to a pistol with 10 ammunition etc. But I have no idea how to do that.
There are many ways to do this. one way to save code and the easiest is the drag and drop method. first you declare a public variable.
public WeaponInfo weaponInfo;
and drag your gameObject that has the script
then you can use variables of that script
weaponInfo.yourVariable;