Esempio n. 1
0
        protected override void OnUpdate()
        {
            float deltaTime = Time.deltaTime;

            for (int i = 0; i < group.Length; i++)
            {
                var fireInput = group.PlayerFireInput[i];
                var weapon    = group.Weapon[i];

                if (fireInput.IsFiringGun)
                {
                    fireInput.GunCoolDown = weapon.Gun.CoolDown;

                    ShotSpawnData shotSpawnData = new ShotSpawnData
                    {
                        Position = weapon.GunPointPosition,
                        Rotation = weapon.GunPointRotation,
                        Faction  = Faction.Type.Player
                    };

                    ShotSpawnSystem.SpawnShot(weapon.Gun, shotSpawnData);
                }
                else
                {
                    fireInput.GunCoolDown = math.max(fireInput.GunCoolDown - deltaTime, 0f);
                }
            }
        }
        public static void SpawnShot(GunBase shot, ShotSpawnData data)
        {
            var newShot = Object.Instantiate(shot);

            var shotPosition = newShot.GetComponent <Position2D>();

            shotPosition.Global = data.Position.Global;
            var shotRotation = newShot.GetComponent <Rotation2D>();

            shotRotation.GlobalZ = data.Rotation.GlobalZ;
            var faction = newShot.GetComponent <Faction>();

            faction.Value = data.Faction;
            var velocity = newShot.GetComponent <Velocity>();

            velocity.Value.x = math.cos(Mathf.Deg2Rad * data.Rotation.GlobalZ) * shot.Speed;
            velocity.Value.y = math.sin(Mathf.Deg2Rad * data.Rotation.GlobalZ) * shot.Speed;
        }