private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.CompareTag("MachineOfPlayer")) { MainMachine machine = collision.gameObject.GetComponent <MainMachine>(); machine.AddHealth(damage); } if (collision.gameObject.CompareTag("Enemy") || collision.gameObject.CompareTag("Player")) { MainCharacter character = collision.gameObject.GetComponent <MainCharacter>(); character.AddHealth(damage); } Destroy(gameObject); }
private void Start() { player = FindObjectOfType <Player>(); machine = GetComponentInParent <MainMachine>(); }