Beispiel #1
0
        private void SpawnViking()
        {
            if (vikings.Count >= maxVikings)
            {
                return;
            }
            if (queueController != null && queueController.QueueSize >= queueController.QueueCapacity)
            {
                return;
            }

            Viking viking = Instantiate(vikingPrefab, transform);

            viking.ChangeModel(Util.RandomElement(vikingModelPrefabs));
            viking.SetScaling(StatScaling);
            viking.Data         = vikingData;
            viking.LeaveTavern += OnLeaveTavern;

            vikings.Add(viking);

            if (queueController != null)
            {
                queueController.AddToQueue(viking);
            }

            VikingSpawned?.Invoke(viking);
        }
Beispiel #2
0
        private void OnLeaveTavern(Viking sender)
        {
            bool removed = vikings.Remove(sender);

            Debug.Assert(removed, "Known viking left");

            Destroy(sender.gameObject);
        }
        private void Awake()
        {
            animator        = GetComponent <Animator>();
            viking          = GetComponentInParent <Viking>();
            vikingTransform = viking.transform;

            sitTransform = new GameObject("Sit Pivot Helper").transform;
            sitTransform.SetParent(vikingTransform);
        }
        public void AddToQueue(Viking viking)
        {
            queue.Add(viking);
            viking.LeaveQueue += HandleOnVikingLeaveQueue;

            // Put the viking one step behind the last spot in the queue
            Vector3 desiredPosition = transform.position + vikingSpacing * queueCapacity * queueDirection;

            viking.transform.position = desiredPosition;
            viking.transform.rotation = Quaternion.LookRotation(-queueDirection);
        }
        private void UpdateQueue()
        {
            Vector3 desiredPosition = transform.position;

            for (int i = 0; i < queue.Count; i++)
            {
                Viking viking = queue[i];
                viking.QueuePosition = i;

                Vector3 currentPosition = viking.transform.position;
                Vector3 newPosition     =
                    Vector3.MoveTowards(currentPosition, desiredPosition, vikingSpeed * Time.deltaTime);
                viking.transform.position = newPosition;

                desiredPosition += queueDirection * vikingSpacing;
            }
        }
 private void HandleOnVikingLeaveQueue(Viking sender)
 {
     queue.Remove(sender);
 }