Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
I need help figuring out how to transfer float values etc. into another script in my Weapons System

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!