/// <summary> /// Stand on a respawn point to activate it. You could play a particle effect of something here. /// </summary> override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) { currentRespawnPoint = this; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // If we are standing on this if (!alreadyAdded && collider.direction == RC_Direction.DOWN) { character.Velocity += speed; alreadyAdded = true; } }
/// <summary> /// Call to recalculate the direction. /// </summary> /// <returns><c>true</c>, if colliders were switched, <c>false</c> otherwise.</returns> virtual public bool UpdateDirection (RaycastCharacterController2D character) { int newDirection = 0; // Always return ledge hang dir - NEW if (character.IsLedgeHanging) { if (character.LedgeHangDirection == RC_Direction.RIGHT) newDirection = 1; if (character.LedgeHangDirection == RC_Direction.LEFT) newDirection = -1; } if (character.characterInput.x > 0.0f) newDirection = 1; if (character.characterInput.x < 0.0f) newDirection = -1; //if (character.Velocity.x > 0.0f) newDirection = 1; //if (character.Velocity.x < 0.0f) newDirection = -1; // If PULLING then return oppoiste direction if (character.State == CharacterState.PULLING) newDirection *= -1; // Special case for startup if (CurrentDirection == 0 && newDirection != 0) { if (newDirection != startingDirection) SwitchColliders(character); } if (newDirection != 0 && newDirection != CurrentDirection) { SwitchColliders(character); CurrentDirection = newDirection; return true; } return false; }
public override void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN && !fallStarted) { fallStarted = true; StartCoroutine(Fall()); } }
public override void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) { characterIsOnMe = true; standTimer = standTime; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (character.FallThroughTimer <= 0.0f && collider.direction == RC_Direction.DOWN && character.characterInput.dropFromPlatform) { character.FallThroughTimer = fallThroughTime; } }
void OnGUI() { controller = (RaycastCharacterController)EditorGUILayout.ObjectField(controller, typeof(RaycastCharacterController), true); controller2D = (RaycastCharacterController2D)EditorGUILayout.ObjectField(controller2D, typeof(RaycastCharacterController2D), true); if (GUILayout.Button(new GUIContent("Recalculate Now", "Press to automatically generate values based on the controller and total height. Some tweaking may be needed."))) { DoCalculations(); } totalLength = NumberLabel("Total Length", totalLength, "Total ladder size in world units."); ladderWidth = NumberLabel("Ladder Width", ladderWidth, "Width of the ladder in world units."); stepSize = NumberLabel("Step Size", stepSize, "Size of each step."); stepDistance = NumberLabel("Step Distance", stepDistance, "Distance between each step."); useLadderTop = GUILayout.Toggle(useLadderTop, new GUIContent("Use Ladder Top", "Have a rigid top the user can stand on.")); if (useLadderTop) { ladderTopDistance = NumberLabel("Ladder Top Offset", ladderTopDistance, "The offset from the top of the ladder in which the 'climb to top' animation is triggered."); } generateMesh = GUILayout.Toggle(generateMesh, new GUIContent("Generate View", "Instantiate a prefab for the ladders view and scale it to the ladder bounds.")); if (generateMesh) { GUILayout.BeginHorizontal(); GUILayout.Label("View Prefab", GUILayout.Width(100)); GUILayout.FlexibleSpace(); GUILayout.Box(new GUIContent("", "Select a prefab to use for the ladder view."), GUILayout.Width(100)); meshPrefab = (GameObject)EditorGUI.ObjectField(GUILayoutUtility.GetLastRect(), meshPrefab, typeof(GameObject), false); GUILayout.EndHorizontal(); } if (GUILayout.Button(new GUIContent("Generate Ladder", "Create the ladder!"))) { GenerateLadder(); } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) { character.Velocity = new Vector3(character.Velocity.x, springForce); } }
/// <summary> /// Respawn the character at the given point. /// </summary> public static void Respawn(RaycastCharacterController2D character) { if (currentRespawnPoint != null) { character.Velocity = Vector2.zero; character.transform.position = currentRespawnPoint.myTransform.position + currentRespawnPoint.respawnPositionOffset; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Hitting from below if (collider.direction == RC_Direction.UP) { if (particles != null) particles.Play(); myCollider.enabled = false; myRenderer.enabled = false; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) { characterIsOnMe = true; standTimer = standTime; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (character.StartedClimbing) { // Move off ladder if (control.dismountWithArrows && character.characterInput.x != 0.0f) { character.Dismount(this); } } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN && !fallStarted) { fallStarted = true; StartCoroutine(Fall()); } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // If we are standing on this if (!alreadyAdded && collider.direction == RC_Direction.DOWN) { character.SetDrag(drag); alreadyAdded = true; } }
void Start() { if (controller == null) { controller = GetComponent <RaycastCharacterController2D>(); } // Register listeners controller.CharacterAnimationEvent += new RaycastCharacterController2D.CharacterControllerEventDelegate(CharacterAnimationEvent); }
/// <summary> /// Trigger the respawn. /// </summary> override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { SimpleHealth2D health = character.GetComponent <SimpleHealth2D>(); if (health != null && health.Health > 0) { health.Die(); } }
override public Transform ParentOnStand (RaycastCharacterController2D character) { if (rigidbody.velocity.y > velocityForFall) { return myTransform; } if (character.transform.parent != null) { character.Velocity = new Vector2 (character.Velocity.x, rigidbody.velocity.y); character.transform.parent = null; } return null; }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (character.StartedClimbing) { // Move off ladder if (control.dismountWithArrows && character.characterInput.x != 0.0f) { character.Dismount(this); } } }
override public Transform ParentOnStand(RaycastCharacterController2D character) { if ((character.StartedClimbing || character.characterInput.y < 0.0f)) { actAsGround = false; } else { actAsGround = true; } return(transform); }
/// <summary> /// Initialise variables. /// </summary> void Start() { health = maxHealth; if (controller == null) { controller = gameObject.GetComponent <RaycastCharacterController2D>(); } if (controller == null) { Debug.LogError("SimpleHealth script not attached to a character"); } }
protected void Load() { if (controller == null) { controller = (RaycastCharacterController)FindObjectOfType(typeof(RaycastCharacterController)); } if (controller2D == null) { controller2D = (RaycastCharacterController2D)FindObjectOfType(typeof(RaycastCharacterController2D)); } DoCalculations(); }
override public Transform ParentOnStand(RaycastCharacterController2D character) { if (rigidbody.velocity.y > velocityForFall) { return(myTransform); } if (character.transform.parent != null) { character.Velocity = new Vector2(character.Velocity.x, rigidbody.velocity.y); character.transform.parent = null; } return(null); }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Hitting from below if (collider.direction == RC_Direction.UP) { if (particles != null) { particles.Play(); } myCollider.enabled = false; myRenderer.enabled = false; } }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Hitting from below (i.e. a headbutt) if (isActive && collider.direction == RC_Direction.UP) { StartCoroutine(DoHit()); if (spawnGameObject != null && !hasSpawned) StartCoroutine(DoSpawn()); else if (spawnGameObject != null) DoBobble(); } // Kill enemies above /*else if (!isActive && collider.direction == RC_Direction.DOWN && character is IEnemy) { ((IEnemy)character).Kill(); } */ }
/// <summary> /// Call to recalculate the direction. /// </summary> /// <returns><c>true</c>, if colliders were switched, <c>false</c> otherwise.</returns> virtual public bool UpdateDirection(RaycastCharacterController2D character) { int newDirection = 0; // Always return ledge hang dir - NEW if (character.IsLedgeHanging) { if (character.LedgeHangDirection == RC_Direction.RIGHT) { newDirection = 1; } if (character.LedgeHangDirection == RC_Direction.LEFT) { newDirection = -1; } } if (character.characterInput.x > 0.0f) { newDirection = 1; } if (character.characterInput.x < 0.0f) { newDirection = -1; } //if (character.Velocity.x > 0.0f) newDirection = 1; //if (character.Velocity.x < 0.0f) newDirection = -1; // If PULLING then return oppoiste direction if (character.State == CharacterState.PULLING) { newDirection *= -1; } // Special case for startup if (CurrentDirection == 0 && newDirection != 0) { if (newDirection != startingDirection) { SwitchColliders(character); } } if (newDirection != 0 && newDirection != CurrentDirection) { SwitchColliders(character); CurrentDirection = newDirection; return(true); } return(false); }
override public Transform ParentOnStand(RaycastCharacterController2D character) { if (character.StartedClimbing) { // Not on the same rope if (!(character.MyParent is Ladder2D && ((Ladder2D)character.MyParent).control == control)) { // Centre on rope if (control.snapToMiddle) { float delta = myTransform.position.x - character.transform.position.x; character.transform.Translate(delta, 0.0f, 0.0f, Space.Self); } } return transform; } return null; }
public void KillFromAbove(HitBox other, Collider me) { if (!hasHitPlayer && other != null && other.simplehealth != null) { // If we can find a character controller RaycastCharacterController2D hero = other.simplehealth.GetComponent <RaycastCharacterController2D>(); if (hero != null) { me.collider.enabled = false; Kill(); hero.Velocity = new Vector2(hero.Velocity.x, bounceVelocity); } } }
override public Transform ParentOnStand(RaycastCharacterController2D character) { if (character.StartedClimbing) { // Not on the same rope if (!(character.MyParent is Ladder2D && ((Ladder2D)character.MyParent).control == control)) { // Centre on rope if (control.snapToMiddle) { float delta = myTransform.position.x - character.transform.position.x; character.transform.Translate(delta, 0.0f, 0.0f, Space.Self); } } return(transform); } return(null); }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Hitting from below (i.e. a headbutt) if (isActive && collider.direction == RC_Direction.UP) { StartCoroutine(DoHit()); if (spawnGameObject != null && !hasSpawned) { StartCoroutine(DoSpawn()); } else if (spawnGameObject != null) { DoBobble(); } } // Kill enemies above /*else if (!isActive && collider.direction == RC_Direction.DOWN && character is IEnemy) { * ((IEnemy)character).Kill(); * } */ }
override public Transform ParentOnStand(RaycastCharacterController2D character) { return(myTransform); }
/// <summary> /// Stand on a respawn point to activate it. You could play a particle effect of something here. /// </summary> override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) currentRespawnPoint = this; }
/// <summary> /// Does this platform want to have this platform become the characters parent. Used for moving platforms. /// </summary> /// <returns> /// Return a transform if you want to reparent the character. /// </returns> virtual public Transform ParentOnStand(RaycastCharacterController2D character) { return null; }
void Start(){ if (controller == null) controller = GetComponent<RaycastCharacterController2D>(); // Register listeners controller.CharacterAnimationEvent += new RaycastCharacterController2D.CharacterControllerEventDelegate (CharacterAnimationEvent); }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (character.FallThroughTimer <= 0.0f && collider.direction == RC_Direction.DOWN && character.characterInput.dropFromPlatform) { character.FallThroughTimer = fallThroughTime; } }
void OnGUI() { controller = (RaycastCharacterController) EditorGUILayout.ObjectField(controller, typeof(RaycastCharacterController), true); controller2D = (RaycastCharacterController2D) EditorGUILayout.ObjectField(controller2D, typeof(RaycastCharacterController2D), true); if (GUILayout.Button (new GUIContent("Recalculate Now", "Press to automatically generate values based on the controller and total height. Some tweaking may be needed."))){ DoCalculations(); } totalLength = NumberLabel("Total Length", totalLength, "Total ladder size in world units."); ladderWidth = NumberLabel("Ladder Width", ladderWidth, "Width of the ladder in world units."); stepSize = NumberLabel("Step Size", stepSize, "Size of each step."); stepDistance = NumberLabel("Step Distance", stepDistance, "Distance between each step."); useLadderTop = GUILayout.Toggle(useLadderTop, new GUIContent("Use Ladder Top", "Have a rigid top the user can stand on.")); if (useLadderTop) ladderTopDistance = NumberLabel("Ladder Top Offset", ladderTopDistance, "The offset from the top of the ladder in which the 'climb to top' animation is triggered."); generateMesh = GUILayout.Toggle(generateMesh, new GUIContent("Generate View", "Instantiate a prefab for the ladders view and scale it to the ladder bounds.")); if (generateMesh) { GUILayout.BeginHorizontal(); GUILayout.Label("View Prefab", GUILayout.Width(100)); GUILayout.FlexibleSpace(); GUILayout.Box (new GUIContent("", "Select a prefab to use for the ladder view."), GUILayout.Width(100)); meshPrefab = (GameObject) EditorGUI.ObjectField(GUILayoutUtility.GetLastRect(), meshPrefab, typeof(GameObject), false); GUILayout.EndHorizontal(); } if (GUILayout.Button (new GUIContent("Generate Ladder", "Create the ladder!"))) { GenerateLadder(); } }
protected void Load() { if (controller == null) controller = (RaycastCharacterController) FindObjectOfType(typeof(RaycastCharacterController)); if (controller2D == null) controller2D = (RaycastCharacterController2D) FindObjectOfType(typeof(RaycastCharacterController2D)); DoCalculations(); }
/// <summary> /// Does this platform want to have this platform become the characters parent. Used for moving platforms. /// </summary> /// <returns> /// Return a transform if you want to reparent the character. /// </returns> virtual public Transform ParentOnStand(RaycastCharacterController2D character) { return(null); }
/// <summary> /// This is called when a platform is hit. Override to implement platform behaviour. /// </summary> /// <param name='collider'> /// The collider that did the hitting. /// </param> /// <param name='character'> /// The character that did the hitting. /// </param> virtual public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Do nothing }
/// <summary> /// Gets the animation for the character. Only called if you have set overrideAnimation to true. /// </summary> /// <returns> /// The animation state. /// </returns> virtual public CharacterState GetAnimationState(RaycastCharacterController2D character) { return(CharacterState.IDLE); }
/// <summary> /// Initialise variables. /// </summary> void Start () { health = maxHealth; if (controller == null) controller = gameObject.GetComponent<RaycastCharacterController2D>(); if (controller == null) Debug.LogError("SimpleHealth script not attached to a character"); }
override public Transform ParentOnStand(RaycastCharacterController2D character) { return myTransform; }
/// <summary> /// Is the character at the appropriate height to trigger the climb top of ladder state. /// </summary> virtual public bool ShouldPlayLedgeClimb (RaycastCharacterController2D character) { return !disableLedgeClimb && character.transform.position.y > ledgeClimbHeight; }
/// <summary> /// Trigger the respawn. /// </summary> override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { SimpleHealth2D health = character.GetComponent<SimpleHealth2D>(); if (health != null && health.Health > 0) { health.Die (); } }
/// <summary> /// Is the character at the appropriate height to trigger the climb top of ladder state. /// </summary> virtual public bool ShouldPlayLedgeClimb(RaycastCharacterController2D character) { return(!disableLedgeClimb && character.transform.position.y > ledgeClimbHeight); }
override public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { if (collider.direction == RC_Direction.DOWN) { character.Velocity = new Vector3(character.Velocity.x, springForce); } }
/// <summary> /// This is called when a platform is hit. Override to implement platform behaviour. /// </summary> /// <param name='collider'> /// The collider that did the hitting. /// </param> /// <param name='character'> /// The character that did the hitting. /// </param> virtual public void DoAction(RaycastCollider2D collider, RaycastCharacterController2D character) { // Do nothing }
virtual protected void SwitchColliders(RaycastCharacterController2D character) { character.SwitchColliders (); }
/// <summary> /// Gets the animation for the character. Only called if you have set overrideAnimation to true. /// </summary> /// <returns> /// The animation state. /// </returns> virtual public CharacterState GetAnimationState(RaycastCharacterController2D character) { return CharacterState.IDLE; }
/// <summary> /// Respawn the character at the given point. /// </summary> public static void Respawn(RaycastCharacterController2D character) { if (currentRespawnPoint != null) { character.Velocity = Vector2.zero; character.transform.position = currentRespawnPoint.myTransform.position + currentRespawnPoint.respawnPositionOffset; } }
virtual protected void SwitchColliders(RaycastCharacterController2D character) { character.SwitchColliders(); }
override public Transform ParentOnStand(RaycastCharacterController2D character) { if ((character.StartedClimbing || character.characterInput.y < 0.0f)) actAsGround = false; else actAsGround = true; return transform; }