private void ToggleAliveOrDeadStatus(bool alive) { //NOTE: ToggleAliveOrDeadStatus is called in AfterDeathProcess and Respawn. Do NOT use it anywhere else. //NOTE: you may add / decrease status vars due to situation. //Suggestion: do NOT write "changes" here, such as live-- or update position / velocity. In my logic they are not seen as status, so write them inside AfterDeathProcess and Respawn. PF2DController controllerPF2D = GetComponent <PF2DController>(); isDead = !alive; if (alive) { //the player has come back to live. isRespawning = false; healthPoint = initialHP; manaPoint = initialMP; if (controllerPF2D) { controllerPF2D.Reset(); } } else { //the player should be dead, totally. healthPoint = 0; if (controllerPF2D) { controllerPF2D.Dead(); } } UpdateHealthPoint(healthPoint); }
protected override void Start() { base.Start(); rb2d = GetComponent <Rigidbody2D> (); pc = GetComponent <PF2DController>(); ActivateEffect(true); player.Circle.GetComponent <SpriteRenderer>().color = showingColor; }
private void OnTriggerExit2D(Collider2D col) { //Debug.Log("Hey yo, " + col.gameObject.name + " has left " + name + "!"); PF2DController controller = col.gameObject.GetComponent <PF2DController>(); if (controller) { ModifyControllerSpeed(controller, false); } }
public void EnableControl(bool allowMove, bool allowJump, bool allowDash) { PF2DController controller = GetComponent <PF2DController>(); if (!controller) { Debug.Log("It seems strange that \"player\" " + name + " doesn't have a PFController.cs. " + "Thus the advanced funct. for controller from " + GetType().Name + "won't work."); return; } controller.allowMovement = allowMove; controller.allowJump = allowJump; controller.allowDash = allowDash; }
public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex) { _obj = animator.gameObject; _rb2d = _obj.GetComponent <Rigidbody2D>(); _col2d = _obj.GetComponent <Collider2D>(); _spr = _obj.GetComponent <SpriteRenderer>(); _controllerPF2d = _obj.GetComponent <PF2DController>(); if (_col2d == null) { Debug.LogWarning(WarningOfMissingTypes(_col2d.GetType().Name)); } if (_rb2d == null) { Debug.LogWarning(WarningOfMissingTypes(_rb2d.GetType().Name)); } if (_controllerPF2d == null) { Debug.LogWarning(WarningOfMissingTypes(_controllerPF2d.GetType().Name)); } }
private void ModifyControllerSpeed(PF2DController controller, bool isMultiply) { //if isMultiply set to false, will divide then if (moveSpeedMultiplier < 0) { Debug.LogWarning(GetType().Name + " of " + name + " warning: moveSpeedMultiplier set < 0. This might cause strange move."); } if (moveSpeedMultiplier == 0) { Debug.LogWarning(GetType().Name + " of " + name + " warning: moveSpeedMultiplier set to 0. To avoid bugs, the script will not modify movingSpeed."); } else { if (thingsHasBeenSpeedUp.Contains(controller) == true && isMultiply == true) { return; //has been multiplied, don't do twice. } if (thingsHasBeenSpeedUp.Contains(controller) == false && isMultiply == true) { Debug.Log("original move speed is " + controller.movingSpeed); controller.movingSpeed *= moveSpeedMultiplier; //p.AddVelocity(new Vector2((moveSpeedMultiplier-1)*rb.velocity.x, (moveSpeedMultiplier - 1) * rb.velocity.y)); //rb.velocity *= moveSpeedMultiplier * (p.isFacingRight ? 1f : -1f); thingsHasBeenSpeedUp.Add(controller); Debug.Log("set multiplied completed. now speed is " + controller.movingSpeed); } else if (thingsHasBeenSpeedUp.Contains(controller) == false && isMultiply == false) { Debug.LogWarning(GetType().Name + " warning: trying to divide speed of " + controller.gameObject.name + " which isn't multiplied before. To avoid bugs the speed will not divide. Check your flow."); } else if (thingsHasBeenSpeedUp.Contains(controller) == true && isMultiply == false) { controller.movingSpeed /= moveSpeedMultiplier; thingsHasBeenSpeedUp.Remove(controller); Debug.Log("set divided completed. now speed is " + controller.movingSpeed); } } }
protected override void Start() { base.Start(); if (player == null) { player = GetComponent <Player>(); if (player == null) { Debug.LogWarning(GetType().Name + " warning: failed to find player on " + name + ". To avoid bugs, this property won't work."); enabled = false; return; } } if (controller2D == null) { controller2D = GetComponent <PF2DController>(); if (controller2D == null) { Debug.LogWarning(GetType().Name + " warning: failed to find controller2D on " + name + ". To avoid bugs, this property won't work."); enabled = false; return; } } }
private void Start() { if (player == null) { if (debugMessage) { Debug.Log(GetType().Name + " of " + name + ": looks like player isn't assigned. Script will try to find one."); } player = GetComponent <Player>(); } if (player) { player.onDead.AddListener(CleanUp); //player.onDead.AddListener(()=>ClearProperty()); if (debugMessage) { Debug.Log("Listener added."); } } if (controller2D == null) { if (debugMessage) { Debug.Log(GetType().Name + " of " + name + ": looks like controller2D isn't assigned. Script will try to find one."); } controller2D = GetComponent <PF2DController>(); } UnitProperty[] checkList = GetComponents <UnitProperty>(); foreach (UnitProperty p in checkList) { if (propertyList.Contains(p) != true) { propertyList.Add(p); } } }