void OnTriggerStay2D(Collider2D other) { //Debug.LogFormat($"We ({name}) collided with a {other.name}"); var maybeMelee = other.gameObject.GetComponentInParent <Melee>(); if (maybeMelee != null) { // No friendly fire if (maybeMelee.faction != faction) { // Dead things don't collide if (IsAlive) { // No stunlock if (!IsStunned()) { //Debug.Log("Ouch! "+ Time.time); if (isAI) { runner.soundMgr.PickAiHurtSound().Play(); } else { runner.soundMgr.soundPlayerHurt.Play(); } SetStunned(); var newStock = runner.InstantiateStock(transform.position); var idealSharesLost = Runner_GameScene.DollarsToShares(damageOnHit); var actualSharesLost = Mathf.Min(idealSharesLost, shares); newStock.quantity = actualSharesLost; if (idealSharesLost > actualSharesLost) { shares = 0; } else { shares -= actualSharesLost; } if (shares <= 0) { Die(); } } } } } var maybeStock = other.gameObject.GetComponentInParent <Stock>(); if (maybeStock != null) { // Dead things don't collide if (IsAlive) { // Stunned things don't pick up Stock if (!IsStunned()) { if (maybeStock.isCollectable) { if (isAI) { runner.soundMgr.soundAiAcquiresStock.Play(); } else { runner.soundMgr.soundPlayerAcquiresStock.Play(); } shares += maybeStock.quantity; Destroy(maybeStock.gameObject); } } } } }
public void InitStartingValues() { shares = Runner_GameScene.DollarsToShares(initialNetWorth); }