When accesing variables in script, it returns 0
Basically I want to make, when player collides with object, that object passes values to player controller and then to gun controller, but when I Debug log variables from pickup in player controller script it returns 0, values for fl_firerate and fl_damage are set in inspector .
// Pickup script
public float fl_firerate ;
public float fl_damage ;
public float getDamage(){
return fl_damage;
}
public float getFireRate(){
return fl_firerate;
And this is part of player script
void OnCollisionEnter2D(Collision2D other) {
if(other.gameObject.tag == "tg_pickUp"){
scr_gunPickUp pickup = other.gameObject.GetComponent<scr_gunPickUp>();
Debug.Log(pickup.getDamage());
// gun.fl_damage = pickup.fl_damage;
// gun.fl_firerate = pickup.fl_firerate;
}
}
It dosent work even when I set values manually in script or when I try to access fl_firerate or fl_damage directly .
Your answer
Follow this Question
Related Questions
How to Reference Other Scripts' Variables in C# 1 Answer
How do I reference an incremented int with one button, that was incremented from another button? 1 Answer
Search for a tag using an Enum 1 Answer
Resources folder empty in Build and public variables NullReferenceException 1 Answer
checking other object variable 1 Answer