コード例 #1
0
        /// <summary>
        /// Swaps patrol for alert guard
        /// </summary>
        public void SwapAgents()
        {
            Guards
            .Zip(GuardsSwap, Tuple.Create)
            .ToList()
            .ForEach(t =>
            {
                var(inPlay, outPlay) = t;
                Rigidbody outPlayRb  = outPlay.GetComponent <Rigidbody>();
                Rigidbody inPlayRb   = inPlay.GetComponent <Rigidbody>();

                outPlayRb.isKinematic = true;
                inPlayRb.isKinematic  = true;

                //move agents
                outPlayRb.transform.position = inPlay.transform.position;
                inPlayRb.transform.position -= new Vector3(0, 100, 0);

                outPlayRb.isKinematic = false;
                inPlayRb.isKinematic  = false;

                // stop their movement
                outPlayRb.velocity = Vector3.zero;
                inPlayRb.velocity  = Vector3.zero;
                //swap lists
                Guards.Remove(inPlay);
                Guards.Add(outPlay);
                GuardsSwap.Remove(outPlay);
                GuardsSwap.Add(inPlay);

                // change Can Move
                inPlay.GetComponent <AbstractGuard>().CanMove  = false;
                outPlay.GetComponent <AbstractGuard>().CanMove = true;
            });
        }