public override void Start()
        {
            // We can add a new component to an entity using the 'Add' method.
            ammoComponent1 = new AmmoComponent();
            Entity.Add(ammoComponent1);

            // We can even add the component a second time
            ammoComponent2 = new AmmoComponent();
            Entity.Add(ammoComponent2);

            // Lets remove all components of type AmmoComponent
            Entity.RemoveAll <AmmoComponent>();


            // When there is no component of this type attached, but we like there to be one, we can create it automatically
            // NOTE: when a component is created like this, the 'Start' method will be called after this script's Update method has executed
            ammoComponent3 = Entity.GetOrCreate <AmmoComponent>();
        }
Beispiel #2
0
        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);
        }