예제 #1
0
        public static GameObject Instantiate(Transform parent, string prefabName, Vector2Int coords)
        {
            var position = LevelBoard.WorldCoords(coords);

            var rotation = Quaternion.identity;

            return(GameObject.Instantiate((GameObject)Resources.Load("Prefabs/Board Items/" + prefabName), position, rotation, parent));
        }
예제 #2
0
        private static GameObject Instantiate(Puzzle puzzle, string prefabName, Vector2Int coords)
        {
            var position = LevelBoard.WorldCoords(coords);

            var rotation = Quaternion.identity;

            var parent = puzzle.transform.GetChild(0);

            return(GameObject.Instantiate((GameObject)Resources.Load("Prefabs/Board Items/" + prefabName), position, rotation, parent));
        }
예제 #3
0
        // Reactivates the Agent
        public void Reactivate(Vector2Int coords)
        {
            this.Reveal();

            this.PlacePiece(this, coords);

            this.transform.position = LevelBoard.WorldCoords(coords);

            this.Active = true;
        }
예제 #4
0
        virtual public bool Move(Vector2Int targetCoords, float minSpeed = 0f)
        {
            var targetPosition = LevelBoard.WorldCoords(targetCoords);

            var speed = Mathf.Max(minSpeed, this.Stats.Speed);

            var maxVelocity = speed / 100f;

            var currentPosition = this.transform.position;

            // If the distance to the Target Position exceeds what can be traveled in one Step
            if (Vector3.Distance(currentPosition, targetPosition) > maxVelocity)
            {
                var dX = targetPosition.x - currentPosition.x;  // Distance to travel (North - South)
                var dZ = targetPosition.z - currentPosition.z;  // Distance to travel (West  - East)

                var norm = (new Vector3(dX, 0, dZ)).normalized; // Normalize the distance vector;

                var rate = Time.deltaTime / EXPECTED_DELTA;
                if (minSpeed == 1f)
                {
                    rate = 1f;
                }

                this.transform.position += norm * ((float)(maxVelocity * rate));  // Apply movement

                return(false);
            }

            // If the Agent is within a one Step distance of the Target Position
            else
            {
                this.transform.position = targetPosition; // Set their position to the Target Position

                return(true);
            }
        }
예제 #5
0
 public Vector3 WorldCoords(Vector2Int position)
 {
     return(LevelBoard.WorldCoords(position));
 }