private void OnCollisionEnter2D(Collision2D other) { if (other.transform.tag != "Untagged" && other.transform.tag != "Ground" && other.transform.tag != "Wall" && other.transform.tag != "Enemy") { return; } GetComponent <Animator>().SetBool("isBreak", true); if (other.transform.tag == "Enemy") { GameObject enemy = other.gameObject; Slider HPbar = enemy.GetComponentInChildren <Slider>(); EnemyController2 EC = enemy.GetComponent <EnemyController2>(); if (!EC.GetIsPotioned()) { HPbar.maxValue *= 3.0f; HPbar.value *= HPbar.maxValue; EC.SetIsPotioned(); } } }
private void OnTriggerStay2D(Collider2D other) { EnemyController ec = other.gameObject.GetComponent <EnemyController>(); if (ec) { ec.GemTouchedVirus(this.gameObject); } else { EnemyController2 ec2 = other.gameObject.GetComponent <EnemyController2>(); ec2.GemTouchedVirus(this.gameObject); } }
private void OnCollisionEnter2D(Collision2D collision) { //-Chaos //What a hell is this? //Why not just disable shuriken-player collisions? //if (collision.gameObject.tag != "Player") //{ if (isRewinding) { return; } if (Stuck) { return; } collisionCount++; if (collision.gameObject.CompareTag("Enemy")) { collisionCount = maxCollisions; EnemyController2 enemy = collision.gameObject.GetComponent <EnemyController2>(); transform.SetParent(enemy.sticker, true); enemy.TakeDamage(damageDealt); } //-Chaos //This is done to stop shuriken immediately after collision //and prevent visual glitches //they still exist though :( if (collisionCount >= maxCollisions) { Stuck = true; rbody.velocity = Vector2.zero; rbody.simulated = false; sounds.PlayStuck(); } else { sounds.PlayBounce(); } //} }
void OnCollisionEnter2D(Collision2D collision) { EnemyController2 enemy = collision.collider.GetComponent <EnemyController2>(); if (enemy != null) { foreach (ContactPoint2D point in collision.contacts) { //Debug.Log (point.normal); Debug.DrawLine(point.point, point.point + point.normal, Color.red, 10); if (point.normal.y >= 0.9f) { velocity = myBody.velocity; velocity.y = jumpVelocity; myBody.velocity = velocity; enemy.Hurt(); } else { Damaged(); } } } }
private void Start() { _spr = GetComponent <SpriteRenderer>(); _anim = GetComponent <Animator>(); _controller = GetComponent <EnemyController2>(); }
// Update is called once per frame void Update() { if (scoreCoins == nrCoins) // nrCoins - total number of coins { gameState = 1; } // AFISARE SCOR if (gameState == 0) { text.text = "SCOR: " + score.ToString(); } else if (gameState == 1) { text.text = "YOU WON"; gameObject.SetActive(false); } else if (gameState == 2) { text.text = "YOU LOST"; gameObject.SetActive(false); } Vector3 scale = transform.localScale; transform.position = Vector3.MoveTowards(transform.position, movePoint.position, moveSpeed * Time.deltaTime); if (Vector3.Distance(transform.position, movePoint.position) <= .05f) { // Contorizare scor if (coins.HasTile(coins.WorldToCell(transform.position))) { score++; scoreCoins++; //Debug.Log(score); } coins.SetTile(coins.WorldToCell(transform.position), null); // Putere if (powers.HasTile(powers.WorldToCell(transform.position))) { EnemyController.ModeChange(); EnemyController2.ModeChange(); } powers.SetTile(powers.WorldToCell(transform.position), null); if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) == 1f) { last_move = 0; if (Input.GetAxisRaw("Horizontal") == -1) { scale.x = 4; } else { scale.x = -4; } if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f), .2f, whatStopsMovement)) { movePoint.position += new Vector3(Input.GetAxisRaw("Horizontal"), 0f, 0f); } } else if (Mathf.Abs(Input.GetAxisRaw("Vertical")) == 1f) { if (Input.GetAxisRaw("Vertical") == 1) { last_move = 1; } else { last_move = 2; } if (!Physics2D.OverlapCircle(movePoint.position + new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f), .2f, whatStopsMovement)) { movePoint.position += new Vector3(0f, Input.GetAxisRaw("Vertical"), 0f); } } else { GetComponent <Animator>().SetTrigger("idle"); } transform.localScale = scale; } else { if (last_move == 0) { GetComponent <Animator>().SetTrigger("move_side"); } else if (last_move == 1) { GetComponent <Animator>().SetTrigger("move_up"); } else { GetComponent <Animator>().SetTrigger("move_down"); } } }