private void OnCollisionEnter(Collision other) { _sword = other.transform.GetComponent <SwordMove>(); _bullet = other.transform.GetComponent <BulletMove>(); if (_bullet != null && other.gameObject.tag == "Player") { HP -= _bullet._damage; _dir = other.transform.forward; StartCoroutine(HitBack(_bullet._hitback)); Destroy(other.gameObject); _hud.BeHit(_bullet._damage); } if (_sword != null && other.gameObject.tag == "Player") { HP -= _sword._damage; _dir = new Vector3((transform.position - other.transform.position).x, 0, (transform.position - other.transform.position).z).normalized; StartCoroutine(HitBack(_sword._hitback)); _sword.GetComponent <BoxCollider>().isTrigger = true; _hud.BeHit(_sword._damage); if (SwardHit != null) { AudioSource.PlayClipAtPoint(SwardHit, transform.position); } } if (other.gameObject.tag == "PlayerBody") { PlayerManager.Instance._currHP -= damage; } }
public void RefreshWeaponName() { List <PackageItems> _weapons = XML.Instance.equipsLoaded; //刷新剑的信息 _sword = _swordPoint.GetComponentInChildren <SwordMove> (); if (_sword._swordName == "") { string _swordName = _swordPoint.transform.GetChild(0).name; for (int i = 0; i < _weapons.Count; i++) { if (_swordName == _weapons[i].name) { _coldTime = _weapons[i].coldTime; break; } } _sword._swordName = _swordName; } //刷新枪的名字,生成子弹的时候读取枪的name _gunName = _gunPoint.transform.GetChild(0).name; for (int i = 0; i < _weapons.Count; i++) { if (_gunName == _weapons[i].name) { _coldTime = _weapons[i].coldTime; _playerHitBack = _weapons[i].playerHitBack; _bulletName = _weapons [i].bulletEffectName; for (int j = 0; j < _bullets.Length; j++) { if (_bulletName == _bullets[j].name) { _bullet = _bullets[j]; } } break; } } //刷新法杖的名字 _magicName = _magicPoint.transform.GetChild(0).name; for (int i = 0; i < _weapons.Count; i++) { if (_magicName == _weapons[i].name) { _coldTime = _weapons[i].coldTime; _playerHitBack = _weapons[i].playerHitBack; _magicBallName = _weapons [i].magicEffectName; _heathUse = _weapons [i].healthUse; for (int j = 0; j < _magicBalls.Length; j++) { if (_magicBallName == _magicBalls[j].name) { _magicBall = _magicBalls[j]; } } break; } } //Debug.Log("shuaxinwuqi2"); }
private void Start() { SwordMove = FindObjectOfType <SwordMove>(); }