Lock a variable

I’m using the following code to add a weapon for some characters:

enter code here	public static Weapons AddShortSword() {				//level	1 cant drop
		Weapons ShortSword = new Weapons();
		
		ShortSword.Name = "Short Sword";
		ShortSword.EquipmentType = 1;
		ShortSword.Damage = 2;
		ShortSword.DamageBonus = 2;
		ShortSword.EnemyType = 2;
		ShortSword.ItemLevel = 1;
		ShortSword.ItemCost = 50;
		ShortSword.MinDamageLow = 2;
		ShortSword.MinDamageHigh = 3;
		ShortSword.MaxDamageLow = 4;
		ShortSword.MaxDamageHigh = 7;
		//trying to lock these
		ShortSword.MinDamage = Random.Range (ShortSword.MinDamageLow, ShortSword.MinDamageHigh);
		ShortSword.MaxDamage = Random.Range (ShortSword.MaxDamageLow, ShortSword.MaxDamageHigh);
		Debug.Log (ShortSword.MinDamage);
		Debug.Log (ShortSword.MaxDamage);
		
		return ShortSword;
	}

Each time I add the weapon the min and max damage changes as expected. But, I am trying to figure out how to have it permanent; yet, still include the Random.Range the first time I add the weapon.

Does anyone know of an approach where when I add this weapon the MinDamage and MaxDamage stays the same from the first time it runs a Random.Range?

thanks

//Declare these as private in the Class which possess AddShortSword()
private bool IsValueLocked=false;
private int LockedMinDamage;
private int LockedMaxDamage;

public static Weapons AddShortSword() 
{ 

  //Use this switch to lock the value
  if(!IsValueLocked)
  {  
     LockedMinDamage=Random.Range (ShortSword.MinDamageLow, ShortSword.MinDamageHigh);
     LockedMaxDamage=Random.Range (ShortSword.MaxDamageLow, ShortSword.MaxDamageHigh);
     IsValueLocked=true;
  }

  //trying to lock these
  ShortSword.MinDamage =LockedMinDamage; 
  ShortSword.MaxDamage =LockedMaxDamage; 

}

Hope this helps… :slight_smile: