// Start is called before the first frame update void Start() { // Gets number of enemies text script _enemyTextScript = FindObjectOfType <EnemyTextScript>(); // Gets components _edible = GetComponent <Edible>(); _harmful = GetComponent <Harmful>(); // Sets up events _edible.CaughtEvent = () => { // Destroy horizontal movement Destroy(GetComponent <HorizontalMovement>()); // Stops us from being harmful _harmful.enabled = false; // Deduct enemy count if (_enemyTextScript != null) { _enemyTextScript.DeductCount(); } // Disables exploder, if we have one Exploder exploder = GetComponent <Exploder>(); if (exploder != null) { exploder.enabled = false; } }; _edible.EatenEvent = () => { }; }
public void OnCollisionEnter(Collision c) { Harmful h = c.transform.GetComponent <Harmful>(); if (h != null) { Life -= h.Damages; } }
//dont override private void OnCollisionEnter(Collision collision) { //stop checking if collision cant be harmful Harmful hurt = collision.gameObject.GetComponent <Harmful>(); if (hurt == null) { return; } //don't get damaged if it cant hurt you if (invulnerableTo.Contains(hurt)) { return; } //account for recent damage damaged = true; secondsSince = 0; damage(hurt.getHarm()); }