private void Update() { if (Target == null) { ShellCollection <UsualBullet> .Destroy(gameObject); } if (Vector3.Distance(transform.position, _startPosition) > LifeDistance) { ShellCollection <UsualBullet> .Destroy(gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { var go = collision.gameObject.GetComponent <IGameplayObject>(); if (go == null || go.AllianceGuid == AllianceGuid) { return; } go.MakeDamage(BaseDamage); ShellCollection <UsualBullet> .Destroy(gameObject); }
public static void InitShell <TShell>( GameObject originalShell, GameObject target, Vector3 startPosition, Guid allianceGuid) where TShell : MonoBehaviour { var shell = ShellCollection <TShell> .Get( originalShell, startPosition, originalShell.transform.rotation); var iShell = shell.GetComponent <IShell>(); var iGameplayObject = shell.GetComponent <IGameplayObject>(); iGameplayObject.AllianceGuid = allianceGuid; iShell.Target = target; iShell.Initiate(); }
private void FixedUpdate() { if (Target == null) { ShellCollection <UsualRocket> .Destroy(gameObject); } if (Homing) { var heading = Target.transform.position - transform.position; _movementBehaviour.SetVelocity(heading.normalized * _movementBehaviour.MaxVelocity); float angle = Mathf.Atan2(_movementBehaviour.Velocity.y, _movementBehaviour.Velocity.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward); } else { if (Vector3.Distance(transform.position, _startPosition) > LifeDistance) { ShellCollection <UsualRocket> .Destroy(gameObject); } } }