Exemplo n.º 1
0
        /// <summary>
        /// Instantiates (if needed) the no going back object that will prevent back movement in the level
        /// </summary>
        protected virtual void InstantiateNoGoingBack()
        {
            if (OneWayLevelMode == OneWayLevelModes.None)
            {
                return;
            }
            // we instantiate the new no going back object
            GameObject newObject = new GameObject();

            newObject.name  = "NoGoingBack";
            newObject.layer = LayerMask.NameToLayer("PlatformsPlayerOnly");
            Vector3 newPosition = Players[0].transform.position;

            if (OneWayLevelMode == OneWayLevelModes.Left)
            {
                newPosition.x -= NoGoingBackThreshold + NoGoingBackColliderSize.x / 2f;
            }
            if (OneWayLevelMode == OneWayLevelModes.Right)
            {
                newPosition.x += NoGoingBackThreshold + NoGoingBackColliderSize.x / 2f;
            }
            if (OneWayLevelMode == OneWayLevelModes.Down)
            {
                newPosition.y -= NoGoingBackThreshold + NoGoingBackColliderSize.y / 2f;
            }
            if (OneWayLevelMode == OneWayLevelModes.Top)
            {
                newPosition.y += NoGoingBackThreshold + NoGoingBackColliderSize.y / 2f;
            }
            newObject.transform.position = newPosition;

            WallClingingOverride wallClingingOverride = newObject.AddComponent <WallClingingOverride> ();

            wallClingingOverride.CanWallClingToThis = false;

            BoxCollider2D collider2D = newObject.AddComponent <BoxCollider2D> ();

            collider2D.size = NoGoingBackColliderSize;

            NoGoingBackObject = newObject.AddComponent <NoGoingBack>();
            NoGoingBackObject.ThresholdDistance       = NoGoingBackThreshold;
            NoGoingBackObject.Target                  = Players [0].transform;
            NoGoingBackObject.OneWayLevelMode         = OneWayLevelMode;
            NoGoingBackObject.NoGoingBackColliderSize = NoGoingBackColliderSize;
            NoGoingBackObject.MinDistanceFromBounds   = NoGoingBackMinDistanceFromBounds;

            if (OneWayLevelKillMode == OneWayLevelKillModes.Kill)
            {
                newObject.AddComponent <KillPlayerOnTouch> ();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialization
        /// </summary>
        protected virtual void Start()
        {
            // we get the camera component
            _camera = GetComponent <Camera>();

            // We make the camera follow the player
            FollowsPlayer = true;
            _currentZoom  = MinimumZoom;

            // we make sure we have a Player
            if ((LevelManager.Instance.Players == null) || (LevelManager.Instance.Players.Count == 0))
            {
                Debug.LogWarning("CameraController : The LevelManager couldn't find a Player character. Make sure there's one set in the Level Manager. The camera script won't work without that.");
                return;
            }

            AssignTarget();

            // if we have a level manager, we grab our level bounds and optionnally our no going back object
            if (LevelManager.Instance != null)
            {
                _levelBounds = LevelManager.Instance.LevelBounds;
                if (LevelManager.Instance.OneWayLevelMode != LevelManager.OneWayLevelModes.None)
                {
                    _noGoingBackObject = LevelManager.Instance.NoGoingBackObject;
                }
                else
                {
                    _noGoingBackObject = null;
                }
            }

            // we store the target's last position
            _lastTargetPosition = Target.position;
            _offsetZ            = (transform.position - Target.position).z;
            transform.parent    = null;


            if (PixelPerfect)
            {
                MakeCameraPixelPerfect();
                GetLevelBounds();
            }
            else
            {
                Zoom();
            }
        }