public override void Start() { // We retrieve the Ammo component that is also attached to the current entity AmmoComponent ammoComponent1 = Entity.Get <AmmoComponent>(); // We can now access public methods and properties of the retrieve component ammoCount1 = ammoComponent1.GetTotalAmmo(); // We now remove the AmmoComponent from our entity. If we try to retrieve it again, null will be returned Entity.Remove <AmmoComponent>(); AmmoComponent ammoComponent2 = Entity.Get <AmmoComponent>(); // Now that 'ammoComponent' is null, we will never be able to retrieve the total ammo if (ammoComponent2 != null) { // This line will never happen ammoCount2 = ammoComponent2.GetTotalAmmo(); } // Add the component again so that it doesn't crash next run Entity.Add(ammoComponent1); }
public override void Update() { DebugText.Print("Total of ammo of the automatically created AmmoComponent3: " + ammoComponent3.GetTotalAmmo().ToString(), new Int2(440, 200)); }