/// <summary> /// KHi đạn va chạm player /// </summary> /// <param name="other"></param> void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player" || other.gameObject.tag == "Enemy") { if (gameObject.name == "CarrotSmall(Clone)") { if (Vector2.Distance(other.gameObject.transform.position, _PosStart) < 0.5f) { return; } } Player player = other.GetComponent <Player>(); if (player._IsCurrent) { return; } if (dot.tag == "Explosion" || dot.tag == "Explosion_Bomp") { _SoundControler.PlayExplosionSound(true); } if (dot.tag == "Explosion_Poison") { _SoundControler.PlayGlassSound(true); } Instantiate(dot, transform.position, transform.rotation); CollionActive(); } if (other.gameObject.tag == "Map") { if (dot.tag == "Explosion" || dot.tag == "Explosion_Bomp") { _SoundControler.PlayExplosionSound(true); } if (dot.tag == "Explosion_Poison") { _SoundControler.PlayGlassSound(true); } Instantiate(dot, transform.position, transform.rotation); CollionActive(); } }
void OnTriggerEnter2D(Collider2D other) { if (!_IsStart) { return; } if (other.gameObject.tag == "Player" || other.gameObject.tag == "Enemy") { _SoundControler.PlayExplosionSound(true); Instantiate(Explose, gameObject.transform.position, Quaternion.identity); Destroy(gameObject); } }
//--------------------------------------- void Update() { //=======Di chuyển số theo gameObject if (isBallThrown && numText != null) { numText.transform.position = gameObject.transform.position; _timeCount += Time.deltaTime; if (_timeCount > 1) { _timeDestroy--; _timeCount = 0; NumberText lbNumText = numText.GetComponentInChildren <NumberText>(); lbNumText.SetNumberText(_timeDestroy); if (_timeDestroy == 0) { Instantiate(_Explosion, transform.position, Quaternion.identity); _SoundControler.PlayExplosionSound(true); //Chuyển turn============================ GameControler gameControler = FindObjectOfType <GameControler>(); if (!gameControler._GameState._IsChangding) { gameControler.ChangeTurn(); } //================== Destroy(numText); Destroy(gameObject); } } return; } if (_GameControler._CheckHit) { return; } if (_GameControler._TypeGame == 0 && _GameControler._GameState._IsEnemyStart) { return; } if ((Camera.main.ScreenToWorldPoint(Input.mousePosition).y < _GameControler.INood.transform.position.y || _UIManager._ListPopup[0].activeSelf) && !isPressed) { return; } if (Input.GetMouseButtonDown(0)) { _posDown = Camera.main.ScreenToWorldPoint(Input.mousePosition); isPressed = true; if (!numText) { createText(); } } else if (Input.GetMouseButtonUp(0)) { isPressed = false; _posUp = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (!isBallThrown) { throwBall(); } } if (isPressed) { Vector3 vel = GetForceFrom(Camera.main.ScreenToWorldPoint(Input.mousePosition), _posDown); //Vector vận tốc ban đầu float angle = Mathf.Atan2(vel.y, vel.x) * Mathf.Rad2Deg; //Góc tạo giữa vel và trục Ox Player player = _GameControler._GameObj.GetComponent <Player>(); angle += _Angle; if (player._Dir == Player.Dir.left) { angle = 360 - angle; } transform.eulerAngles = new Vector3(0, 0, angle); setTrajectoryPoints(transform.position, vel / gameObject.GetComponent <Rigidbody2D>().mass); } }