Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda