/// protected override void Initialization() { if (LevelManager.Instance.Players.Count == 0) { Debug.LogError("No player found!"); return; } if (_controller == null) { _controller = this.gameObject.GetComponent <CorgiController>(); thisCharacter = this.gameObject.GetComponent <Character>(); } else { _controller = this.gameObject.GetComponentInParent <CorgiController>(); thisCharacter = this.gameObject.GetComponentInParent <Character>(); } _characterHorizontalMovement = thisCharacter?.FindAbility <CharacterHorizontalMovement>(); _characterRun = thisCharacter?.FindAbility <CharacterRun>(); _characterJump = thisCharacter?.FindAbility <CharacterJump>(); _jetpack = thisCharacter?.FindAbility <CharacterJetpack>(); thisCharacter.MovementState.ChangeState(CharacterStates.MovementStates.Idle); }
/// <summary> /// On trigger exit, we lose all reference to the controller and character /// </summary> /// <param name="collision"></param> protected virtual void OnTriggerExit2D(Collider2D collider) { _controller = collider.gameObject.MMGetComponentNoAlloc <CorgiController>(); _character = collider.gameObject.MMGetComponentNoAlloc <Character>(); if (_controller == null) { return; } bool found = false; int index = 0; int counter = 0; foreach (SurfaceModifierTarget target in _targets) { if (target.TargetController == _controller) { index = counter; found = true; } counter++; } if (found) { if (ResetForcesOnExit) { _controller.SetForce(Vector2.zero); } _targets[index].TargetAffectedBySurfaceModifier = false; } }
private void OnTriggerEnter2D(Collider2D col) { if (col.tag.Equals("Player")) { _life = GameObject.FindGameObjectWithTag("hearts").GetComponent <Life>(); AudioSource.PlayClipAtPoint(takeCoinSound, transform.position, 0.6f); //SoundManager.Instance.PlaySound(takeCoinSound, transform.position); Instantiate(particles, transform.position, transform.rotation); CorgiController controller = col.GetComponent <CorgiController>(); if (controller == null) { return; } Health playerLife = controller.GetComponent <Health>(); if (playerLife.CurrentHealth != 300) { playerLife.CurrentHealth += 25; _life.UpdateLife(playerLife.CurrentHealth); } Score.score += CoinsPoints; Destroy(transform.gameObject); } }
protected virtual void OnTriggerEnter2D(Collider2D collider) { // if the object that collides with the teleporter is on its ignore list, we do nothing and exit. if (_ignoreList.Contains(collider.transform)) { return; } if (collider.GetComponent <Character>() != null) { _player = collider.GetComponent <Character>(); _controller = collider.GetComponent <CorgiController>(); lucyHorizontalMovement = collider.GetComponent <LucyHorizontalMovement>(); } //if this teleporter is on top of the doorway, set a bool to true and set the player collider to the value that has collided with this trigger. if (TopSideTeleporter == true) { if (collider.GetComponent <Character>() != null) { StandingOnTopSide = true; _thePlayerCollider = collider; } } if (BottomSideTeleporter == true) { if (collider.GetComponent <Character>() != null) { EnteringUnderside = true; _thePlayerCollider = collider; } } }
/// <summary> /// Triggered when something enters the teleporter /// </summary> /// <param name="collider">Collider.</param> protected override void OnTriggerEnter2D(Collider2D collider) { // if the object that collides with the teleporter is on its ignore list, we do nothing and exit. if (_ignoreList.Contains(collider.transform)) { return; } //if the player is on the top side, set this to true StandingOnDoorTop |= TopSideTeleporter; if (collider.GetComponent <Character>() != null) { _player = collider.GetComponent <Character>(); _controller = collider.GetComponent <CorgiController>(); lucyHorizontalMovement = collider.GetComponent <LucyHorizontalMovement>(); } // if the teleporter is supposed to only affect the player (well, corgiControllers), we do nothing and exit if (OnlyAffectsPlayer || !AutoActivation) { base.OnTriggerEnter2D(collider); } else { if ((TopSideTeleporter == false) && (BottomSideTeleporter == false)) { Teleport(collider); } } }
/// <summary> /// Sets the weapon's owner /// </summary> /// <param name="newOwner">New owner.</param> public virtual void SetOwner(Character newOwner, CharacterHandleWeapon handleWeapon) { Owner = newOwner; if (Owner != null) { CharacterHandleWeapon = handleWeapon; _characterGravity = Owner.GetComponent <CharacterGravity>(); _characterHorizontalMovement = Owner.GetComponent <CharacterHorizontalMovement>(); _controller = Owner.GetComponent <CorgiController>(); if (CharacterHandleWeapon.AutomaticallyBindAnimator) { if (CharacterHandleWeapon.CharacterAnimator != null) { _ownerAnimator = CharacterHandleWeapon.CharacterAnimator; } if (_ownerAnimator == null) { _ownerAnimator = CharacterHandleWeapon.gameObject.MMGetComponentNoAlloc <Character>().CharacterAnimator; } if (_ownerAnimator == null) { _ownerAnimator = CharacterHandleWeapon.gameObject.MMGetComponentNoAlloc <Animator>(); } } } }
/// <summary> /// Describes what happens when colliding with a damageable object /// </summary> /// <param name="health">Health.</param> protected virtual void OnCollideWithDamageable(Health health) { // if what we're colliding with is a CorgiController, we apply a knockback force _colliderCorgiController = health.gameObject.MMGetComponentNoAlloc <CorgiController>(); ApplyDamageCausedKnockback(); OnHitDamageable?.Invoke(); HitDamageableFeedback?.PlayFeedbacks(this.transform.position); if ((FreezeFramesOnHitDuration > 0) && (Time.timeScale > 0)) { MMFreezeFrameEvent.Trigger(Mathf.Abs(FreezeFramesOnHitDuration)); } // we apply the damage to the thing we've collided with _colliderHealth.Damage(DamageCaused, gameObject, InvincibilityDuration, InvincibilityDuration); if (_colliderHealth.CurrentHealth <= 0) { OnKill?.Invoke(); } SelfDamage(DamageTakenEveryTime + DamageTakenDamageable); }
/// <summary> /// Triggered when a CorgiController collides with the surface /// </summary> /// <param name="collider">Collider.</param> public virtual void OnTriggerStay2D(Collider2D collider) { _controller = collider.gameObject.MMGetComponentNoAlloc <CorgiController>(); _character = collider.gameObject.MMGetComponentNoAlloc <Character>(); if (_controller == null) { return; } bool found = false; foreach (SurfaceModifierTarget target in _targets) { if (target.TargetController == _controller) { found = true; target.TargetAffectedBySurfaceModifier = true; } } if (!found) { SurfaceModifierTarget newSurfaceModifierTarget = new SurfaceModifierTarget(); newSurfaceModifierTarget.TargetController = _controller; newSurfaceModifierTarget.TargetCharacter = _character; newSurfaceModifierTarget.TargetAffectedBySurfaceModifier = true; _targets.Add(newSurfaceModifierTarget); } }
/// <summary> /// Performs the stomp. /// </summary> /// <param name="corgiController">Corgi controller.</param> protected virtual void PerformStomp(CorgiController corgiController) { if (DamageCausedKnockbackType == KnockbackStyles.SetForce) { corgiController.SetForce(KnockbackForce); } if (DamageCausedKnockbackType == KnockbackStyles.AddForce) { corgiController.AddForce(KnockbackForce); } if (_health != null) { _health.Damage(DamagePerStomp, corgiController.gameObject, InvincibilityDuration, InvincibilityDuration); } // if what's colliding with us has a CharacterJump component, we reset its JumpButtonReleased flag so that the knockback effect is applied correctly. CharacterJump _collidingCharacterJump = corgiController.gameObject.MMGetComponentNoAlloc <CharacterJump>(); if (_collidingCharacterJump != null) { _collidingCharacterJump.ResetJumpButtonReleased(); if (ResetNumberOfJumpsOnStomp) { _collidingCharacterJump.ResetNumberOfJumps(); } } }
/// <summary> /// Makes sure we have a controller, resets forces if needed, applies horizontal and vertical force if needed /// </summary> /// <param name="collider"></param> protected virtual void ApplyForce(Collider2D collider) { _controller = collider.gameObject.MMGetComponentNoAlloc <CorgiController>(); if (_controller == null) { return; } // reset forces if needed if (ResetForces) { _controller.SetForce(Vector2.zero); } // horizontal force if (Time.time - _lastForceAppliedAt.x > ForceApplicationCooldownDuration.x) { _controller.AddHorizontalForce(AddedForce.x); _lastForceAppliedAt.x = Time.time; } // vertical force if (Time.time - _lastForceAppliedAt.y > ForceApplicationCooldownDuration.y) { _controller.AddVerticalForce(AddedForce.y); _lastForceAppliedAt.y = Time.time; } }
/// <summary> /// When exiting collision with something, we check if it's a player, and in that case we set our flag accordingly /// </summary> /// <param name="collider">Collider.</param> public virtual void OnTriggerExit2D(Collider2D collider) { CorgiController controller = collider.GetComponent <CorgiController>(); if (controller == null) { return; } _collidingWithPlayer = false; _collidingController = null; if (StayAnimated) { anim.SetBool("ElevatorMoving", true); } if (ScriptActivated) { anim.SetBool("ElevatorMoving", false); } else { anim.SetBool("ElevatorMoving", true); } anim.SetBool("ElevatorStuck", false); alreadyPlayedStuckSfx = false; alreadyPlayedMoveSfx = false; }
protected void createDialogeBox(CorgiController character) { // Remove the DialogeBox if exists if (_dialogueBox) { Destroy(_dialogueBox.gameObject); } Transform go = character.gameObject.GetComponent <Transform>(); // we instantiate the dialogue box GameObject dialogueObject = (GameObject)Instantiate(Resources.Load("GUI/DialogueBox")); _dialogueBox = dialogueObject.GetComponent <DialogueBox>(); // add it to owner, to follow it around _dialogueBox.transform.SetParent(character.transform); // we set its position _dialogueBox.transform.position = new Vector2(go.position.x, go.position.y + dialogue_offset.y); // we set the color's and background's colors _dialogueBox.ChangeColor(TextBackgroundColor, TextColor); // if it's a button handled dialogue, we turn the A prompt on _dialogueBox.ButtonActive(ButtonHandled); // if we don't want to show the arrow, we tell that to the dialogue box if (!ArrowVisible) { _dialogueBox.HideArrow(); } }
/// <summary> /// When the input button is pressed, we check whether or not the zone can be activated, and if yes, trigger ZoneActivated /// </summary> public virtual void TriggerButtonAction() { if (!CheckNumberOfUses()) { PromptError(); return; } // if we can only activate this zone when grounded, we check if we have a controller and if it's not grounded, // we do nothing and exit if (CanOnlyActivateIfGrounded) { if (_currentCharacter != null) { CorgiController controller = _currentCharacter.gameObject.GetComponentNoAlloc <CorgiController>(); if (controller != null) { if (!controller.State.IsGrounded) { return; } } } } ActivateZone(); }
/// <summary> /// On start, we get the various components /// </summary> protected virtual void Start() { _boxCollider = this.gameObject.GetComponent <BoxCollider2D>(); _controller = this.gameObject.GetComponent <CorgiController>(); _health = this.gameObject.GetComponent <Health>(); _hitsStorage = new RaycastHit2D[NumberOfRays]; }
protected virtual void OnTriggerEnter2D(Collider2D collider) { // if the object that collides with the teleporter is on its ignore list, we do nothing and exit. if (_ignoreList.Contains(collider.transform)) { return; } if (collider.GetComponent <Character>() != null) { _player = collider.GetComponent <Character>(); playerAnimator = collider.GetComponent <Animator>(); _characterPause = collider.GetComponent <CharacterPause>(); _controller = collider.GetComponent <CorgiController>(); _lucyHealth = collider.GetComponent <LucyHealth>(); } if (_player != null) { if (_player.CharacterType == Character.CharacterTypes.Player) { if (_controller.State.IsGrounded) { StartCoroutine(SaveGameEffect()); _lucyHealth.ResetHealthToMaxHealth(); } } AddToIgnoreList(collider.transform); } }
/// <summary> /// Casts the rays above to detect stomping /// </summary> protected virtual void CastRaysAbove() { if (_health != null) { if (_health.CurrentHealth <= 0) { return; } } bool hitConnected = false; _hitConnectedIndex = 0; InitializeRay(); // we cast rays above our object to check for anything trying to stomp it for (int i = 0; i < NumberOfRays; i++) { Vector2 rayOriginPoint = Vector2.Lerp(_verticalRayCastStart, _verticalRayCastEnd, (float)i / (float)(NumberOfRays - 1)); _hitsStorage[i] = MMDebug.RayCast(rayOriginPoint, this.transform.up, RaycastLength, PlayerMask, Color.gray, true); if (_hitsStorage[i]) { hitConnected = true; _hitConnectedIndex = i; break; } } // if we connect with something, we check to see if it's a corgicontroller, and if that's the case, we get stomped if (hitConnected) { // if the player is not hitting this enemy from above, we do nothing if (!HitIsValid()) { return; } CorgiController collidingCorgiController = _hitsStorage[_hitConnectedIndex].collider.gameObject.MMGetComponentNoAlloc <CorgiController>(); Character collidingCharacter = _hitsStorage[_hitConnectedIndex].collider.gameObject.MMGetComponentNoAlloc <Character>(); if (collidingCorgiController != null) { if (StomperMustBeAlive && (collidingCharacter != null) && (collidingCharacter.ConditionState.CurrentState != CharacterStates.CharacterConditions.Normal)) { return; } // if the player is not going down, we do nothing and exit if (collidingCorgiController.Speed.y >= 0) { return; } PerformStomp(collidingCorgiController); } } }
/// <summary> /// On init we grab our CharacterFly ability /// </summary> protected override void Initialization() { _characterFly = this.gameObject.GetComponent <CharacterFly>(); _controller = this.gameObject.GetComponent <CorgiController>(); _phage = this.gameObject.GetComponent <Transform>(); wobbler = this.gameObject.GetComponent <PhageWobbler>(); }
/// <summary> /// On Start we grab our various components /// </summary> protected virtual void Start() { _otherComponents = GetComponents <MonoBehaviour>(); _controller = GetComponent <CorgiController>(); _collider2D = GetComponent <Collider2D>(); _renderer = GetComponent <Renderer>(); _initialPosition = this.transform.position; }
/// <summary> /// Attaches a pusher controller to this pushable object /// </summary> /// <param name="pusher"></param> public virtual void Attach(CorgiController pusher) { if (!Grounded) { return; } Pusher = pusher; }
/// <summary> /// On init we grab our AI components /// </summary> protected override void Initialization() { _controller = GetComponent <CorgiController>(); _character = GetComponent <Character>(); _characterHorizontalMovement = GetComponent <CharacterHorizontalMovement>(); _characterJump = GetComponent <CharacterJump>(); _direction = _character.IsFacingRight ? Vector2.right : Vector2.left; }
/// <summary> /// Triggered when a CorgiController touches the platform, applys a vertical force to it, propulsing it in the air. /// </summary> /// <param name="controller">The corgi controller that collides with the platform.</param> protected virtual void OnTriggerEnter2D(Collider2D collider) { _controller = collider.GetComponent <CorgiController>(); if (_controller == null) { return; } }
/// <summary> /// On init we grab our AI components /// </summary> public override void Initialization() { base.Initialization(); downRay = new RaycastHit2D(); _controller = GetComponent <CorgiController>(); _character = LevelManager.Instance.PlayerPrefabs[0]; _characterHorizontalMovement = GetComponent <CharacterHorizontalMovement>(); }
// Use this for initialization void Start() { cg = GetComponent <CorgiController>(); hinge = GetComponent <DistanceJoint2D>(); lineRenderer = GetComponent <LineRenderer>(); lineRenderer.SetPosition(1, transform.position); lineRenderer.enabled = false; hinge.enabled = false; }
/// <summary> /// Triggered when a CorgiController exits the platform /// </summary> /// <param name="controller">The corgi controller that collides with the platform.</param> public virtual void OnTriggerExit2D(Collider2D collider) { CorgiController controller = collider.GetComponent <CorgiController>(); if (controller == null) { return; } }
/// <summary> /// Initialization /// </summary> public virtual void Start() { _character = GetComponent <Character>(); _controller = GetComponent <CorgiController>(); _boxCollider = GetComponent <BoxCollider2D>(); if (LevelManager.Instance != null) { } }
void OnTriggerEnter2D(Collider2D col) { controller = col.GetComponent <CorgiController>(); score.increaseScore(controller.GetComponent <Health>().CurrentHealth); // we add the number of life to score playTime = GameObject.Find("TimerText").GetComponent <Timer>().playTime; Player.GetComponent <DisplayCharacterOnEndLevel>().enabled = true; /* * //old method based on time + score * int inc = 0; * if (LvlManager.ObjectiveTime > playTime) { * inc = (LvlManager.ObjectiveTime - playTime) * multiplierTimePositive; * } else { * inc = (LvlManager.ObjectiveTime - playTime) * multiplierTimeNegative; * } * score.increaseScore(inc); * Debug.Log (LvlManager.ObjectiveTime + "s " + playTime + "s = " + inc +" score added. Score total now "+score.score+"."); */ PlayerPrefs.SetInt("CurrentLevelScore", score.score); PlayerPrefs.SetInt("CurrentTimer", playTime); PlayerPrefs.SetString("TimerText", GameObject.Find("TimerText").GetComponent <Text>().text); if (SceneManager.GetActiveScene().name == "Tutorial") { GameObject.FindGameObjectWithTag("Player").SetActive(false); HudModifiable.SetActive(false); SVInfoPanel.SetActive(false); VideoOutroPanel.SetActive(true); } else { if (PlayerPrefs.GetString("Difficulty").Equals("easy") && VideoOutroPanel != null) { GameObject.FindGameObjectWithTag("Player").SetActive(false); HudModifiable.SetActive(false); SVInfoPanel.SetActive(false); VideoOutroPanel.SetActive(true); } else { ActionOnTrigger(); } } string AvatarName = PlayerPrefs.GetString("AvatarName"); string GeneName = PlayerPrefs.GetString("GeneName"); // Sending Analytics event Analytics.CustomEvent("level_completed", new Dictionary <string, object> { { "avatar", "Avatar " + AvatarName }, { "gene", GeneName } } ); }
/// <summary> /// Initialization /// </summary> protected virtual void Awake() { _ignoredGameObjects = new List <GameObject>(); _health = GetComponent <Health>(); _corgiController = GetComponent <CorgiController> (); _boxCollider2D = GetComponent <BoxCollider2D>(); _circleCollider2D = GetComponent <CircleCollider2D>(); _gizmosColor = Color.red; _gizmosColor.a = 0.25f; }
/// <summary> /// On exit we get rid of our controller /// </summary> /// <param name="collider"></param> protected virtual void OnTriggerExit2D(Collider2D collider) { if (_controller != null) { if (collider.gameObject == _controller.gameObject) { _controller = null; } } }
/// <summary> /// Initialization /// </summary> protected virtual void Awake() { _ignoredGameObjects = new List <GameObject>(); _health = this.gameObject.GetComponent <Health>(); _corgiController = this.gameObject.GetComponent <CorgiController> (); _boxCollider2D = this.gameObject.GetComponent <BoxCollider2D>(); _circleCollider2D = this.gameObject.GetComponent <CircleCollider2D>(); _gizmosColor = Color.red; _gizmosColor.a = 0.25f; InitializeFeedbacks(); }
/// <summary> /// Detaches the current pusher object from this pushable object /// </summary> /// <param name="pusher"></param> public virtual void Detach(CorgiController pusher) { if (pusher == Pusher) { Pusher = null; if (_corgiController != null) { _corgiController.SetForce(Vector2.zero); } } }
/// <summary> /// Initialization /// </summary> protected virtual void Awake() { // we get the CorgiController2D component _controller = GetComponent<CorgiController>(); // initialize the start position _startPosition = transform.position; // initialize the direction _direction = GoesRightInitially ? Vector2.right : -Vector2.right; _initialDirection = _direction; _initialScale = transform.localScale; _holeDetectionOffset = new Vector3(1, -1f, 0); }
protected virtual void Start() { // getting the mask sensor _maskSensor = GetComponent<MaskSensor>(); // we get the CorgiController2D component _controller = GetComponent<CorgiController>(); // we get the player from its tag _playerTransform = GameManager.Instance.Player.transform; if (_playerTransform == null || _controller == null || _maskSensor == null) { Debug.LogError ("Destroying enemy object " + gameObject.name + " since its variables are not initialized."); GameObject.Destroy (this); } ChangeDirection(); }