private void Awake() { playerAi = GetComponent <PlayerAi>(); rigidbody = GetComponent <Rigidbody2D>(); collider = GetComponent <Collider2D>(); healthMechanic = GetComponent <HealthMechanic>(); healthMechanic.Register(OnHealthUpdate); }
void Update() { RotateObject(wisp); Shoot(); healthManager = transform.parent.GetComponent <HealthMechanic>(); UpdateIntensityOfBackLight(); }
// ------------------------------------------------------------------ public void SetData(ICharacterData data, IPlayer player) { Data = data; Attributes = new CharAttributes(Data, player); Health = new HealthMechanic(this); Damage = new DamageMechanic(this); Heal = new HealMechanic(this); Death = new DeathMechanic(this); AttackTurn = new AttackCharacterMechanic(this); }
// Use this for initialization void Start() { monsterPosition = GetComponent <Transform>(); healthManager = GetComponent <HealthMechanic>(); lightSources = new List <GameObject>(); foreach (GameObject go in GameObject.FindObjectsOfType(typeof(GameObject))) { if (go.name == "Light Source") { lightSources.Add(go); } } }
void Start() { healthManager = GetComponent <HealthMechanic>(); }
/// <summary> /// Check whether fireball is colliding with the specified target/targets and if so, remove the needed health. /// </summary> /// <param name="collision">Reference to the collision.</param> private void OnCollisionEnter2D(Collision2D collision) { Vector3 bulletSize = transform.localScale; // If there are no shooting targets added to the array, exit the collision detection. if (shootingTargets == null) { return; } foreach (GameObject target in shootingTargets) { if (collision.collider.gameObject == target) { HealthMechanic targetHealthMechanic = target.GetComponent <HealthMechanic>(); targetHealthMechanic.LoseHealth(bulletSize); } } if (collision.collider.tag == "HealingSource") { if (shootingSource.tag == "Player") { // Disable all movement and visuals of the fireball in order to smoothly increase the intensity of the hit candle. // Hide the fireball. gameObject.GetComponent <Renderer>().enabled = false; // Stop the falling of the fireball - keep it in its last position. gameObject.GetComponent <Rigidbody2D>().gravityScale = 0; for (int index = 0; index < transform.childCount; index++) { // Disable all child elements of the fireball. transform.GetChild(index).gameObject.SetActive(false); } Light lightSource = collision.collider.gameObject.transform.GetComponent <Light>(); // Smoothly increase the light of the candle. StartCoroutine(LightCandle(lightSource, 5.0f, 6.0f)); } } if (collision.collider.tag == "RopePiece") { BurningScript burningScript = collision.collider.gameObject.GetComponent <BurningScript>(); burningScript.IsBurning = true; } if (collision.collider.tag == "CrackedPillar") { CrackedPillarBehaviour pillarScript = collision.collider.gameObject.GetComponent <CrackedPillarBehaviour>(); pillarScript.runDestruction = true; } // Whenever the fireball collides with any other game object from the above - destroy. // Exclude elements with tag HealingSource from this check in order to smoothly increase candle ligth and then destroy. if (collision.collider.tag != shootingSource.tag && collision.collider.tag != "HealingSource") { Destroy(gameObject); } }