public virtual void TakeDamage(int _damage) { body.hp -= _damage; if (body.hp <= 0) { EnemyBody _newBody = (EnemyBody)body.Clone(); _newBody.hp = _newBody.startingHp; if (Random.Range(0f, 1f) <= bodySpawnChance) { GameObject corpse = Instantiate(corpsePrefab, transform.position, Quaternion.identity); corpse.GetComponent <Corpse>().originalBody = _newBody; corpse.transform.rotation = Quaternion.Euler(transform.rotation.x, transform.rotation.y, rb.rotation); } Destroy(gameObject); } }
public void Interact(PlayerController _player) { Material _newMaterial = new Material(originalBody.material); EnemyBody _newBody = (EnemyBody)originalBody.Clone(); _newBody.parent = _player.gameObject; _newMaterial.color = _player.originalMaterial.color; if (_player.body != null) { _player.body.Discard(_player); } _player.body = _newBody; _player.GetComponent <SpriteRenderer>().sprite = originalBody.sprite; _player.GetComponent <SpriteRenderer>().material = _newMaterial; _player.transform.position = transform.position; _player.transform.rotation = transform.rotation; Destroy(gameObject); }