private void OnTriggerEnter2D(Collider2D other) { if (other.ToString().Contains("Asteroid")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); AsteroidHealth targetHealth = other.GetComponent <AsteroidHealth>(); AsteroidMovement targetSpeed = other.GetComponent <AsteroidMovement>(); if (targetHealth.getHealth() % numberValue == 0) { targetHealth.takeDamage(numberValue); } else { targetSpeed.ChangeSpeed(speedMultiplier); } } else if (other.ToString().Contains("AlienShip")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); } else if (other.ToString().Contains("Power")) { gameObject.transform.position = new Vector2(15, 20); Destroy(gameObject, 0.5f); } }
void Start() { GameData.asteroidMotion = true; asteroidRigid = GetComponent <Rigidbody2D>(); transform.position = new Vector2(x_pos, y_pos); health = GetComponent <AsteroidHealth>(); }
private void Awake() { FindObjectOfType <ScreenWrappingManager>()?.AddToWrap(transform); m_Rigidbody = GetComponent <Rigidbody2D>(); m_SpriteRenderer = GetComponent <SpriteRenderer>(); m_AsteroidHealth = GetComponent <AsteroidHealth>(); m_DestroyManager = GetComponent <IDestroyManager>(); m_DestroyManager.Init(m_AsteroidHealth, m_AsteroidsSpawnAmount, m_PushForceSpawnedAsteroids); }
private void OnTriggerEnter(Collider other) { AsteroidHealth asteroidHealth = other.gameObject.GetComponent <AsteroidHealth>(); if (asteroidHealth != null) { asteroidHealth.DealDamage(damage); } GameObject.Destroy(gameObject); }