I have a player object, inside it is(children object) an armor object. Armor is different, it has hp, it affects the speed.
I want to transfer to player’s hp, speed the speed of the armor, but I can not get them, I only get 0.
Although in the armor object, I can see through the inspector that the data is there.
public class HealthPlayer: MonoBehaviour
{
[SerializeField] private int health;
public int Health { get => health; set => health = value; }
}
Try to spawn player:
GameObject Player = Instantiate(playerTankPrefab, transform.position, playerTankPrefab.transform.rotation);
Player.transform.position = new Vector3(groundPosX, groundPosY);
Player.GetComponent<Movement>().Speed = Player.GetComponentInChildren<Armor>().Speed;
Player.GetComponent<HealthPlayer>().Health = Player.GetComponentInChildren<Armor>().Health;
Armor creating onEnable():
void RandomArmor()
{
ArmorDefinition currentArmor = armors[Random.Range(0, 2)];
if (GetComponentInParent<EnemyController>())
spriteRendererArmor.sprite = currentArmor.ArmorSpriteEnemy;
else
spriteRendererArmor.sprite = currentArmor.AmorSpritePlayer;
Level = currentArmor.Level;
Speed = currentArmor.Speed;
Health = currentArmor.Health;
}
Pls, I really need help!!!