Hello everyone,
I’m new to Unity and currently doing some exercises from a YouTube tutorial series by VegetarianZombie. Everthing has been going great so far, but now I have encountered an issue. I want to set a value to a private int from another script.
This works great, as long as the Set-Value funct. and the Return-Value funct. are being called from the same function. However, if I simply set the value of the int at void Start() and later on want to call it from OnDisable(), it seems to have disappeared, or not to have been saved at all.
Here, I want the cube to acces playerStruct.
What is weird that the value gets printed without an issue by the Debug.Log in Start(), but I just can’t figure out what is wrong with OnDisable().
Thank you so much for your help guys. Have a good one!
playerStruct
namespace Tutorial.Alien
{
public struct Adversary
{
private int damage;
private int Healthpool;
private bool IsAlive;
public void SetDamage(int damage)
{
this.damage = damage;
}
public int GetDamage()
{
return damage;
}
}
}
cube - script
using System.Collections;
using System.Collections.Generic;
using Tutorial.Alien;
using UnityEngine;
public class cube : MonoBehaviour
{
Adversary Alien;
void Start()
{
Adversary Alien = new Adversary();
Alien.SetDamage(100);
Debug.Log(Alien.GetDamage());
}
void OnDisable()
{
Debug.Log("The alien deals " + Alien.GetDamage () + " points of damage.");
}
}
EDIT: healthpool and IsAlive don’t matter of course, I want to get damage right first