// Start is called before the first frame update void OnTriggerStay2D(Collider2D other) { NewBehaviourScript controller = other.GetComponent <NewBehaviourScript>(); #pragma warning disable CS0642 // Possible mistaken empty statement if (!(controller != null)) { ; } #pragma warning restore CS0642 // Possible mistaken empty statement { controller.ChangeHealth(-1); } }
// Start is called before the first frame update void OnTriggerEnter2D(Collider2D other) { NewBehaviourScript controller = other.GetComponent <NewBehaviourScript>(); if (controller != null) { #pragma warning disable CS0642 // Possible mistaken empty statement if (controller != null) { ; } #pragma warning restore CS0642 // Possible mistaken empty statement } { controller.ChangeHealth(1); Destroy(gameObject); } }
// Update is called once per frame void Update() { if (!broken) { return; } timer -= Time.deltaTime; if (timer < 0) { direction = -direction; } timer = changeTime; Vector2 position = rigidbody2d.position; if (vertical) { position.y = position.y + Time.deltaTime * speed; animator.SetFloat("Move X", 0); animator.SetFloat("Move Y", direction); } else { position.x = position.x + Time.deltaTime * speed; animator.SetFloat("Move X", direction); animator.SetFloat("Move Y", 0); } rigidbody2d.MovePosition(position); void OnCollisionEnter2D(Collision2D other) { NewBehaviourScript player = other.gameObject.GetComponent <NewBehaviourScript>(); if (player != null) { player.ChangeHealth(-1); } } }