/// <summary> /// 武器开火 /// </summary> /// <param name="mouseDir"></param> public void Fire(Vector2 mouseDir) { //播放动画和音效 anim.SetTrigger("Shoot"); audio.Play(); switch (bulletPref.GetComponent <Bullet>().bulletType) { case Bullet.BulletType.Normal: if (propManager.normalBullet < 1) { return; } --propManager.normalBullet; propManager.UpdateDisplay(); break; case Bullet.BulletType.Fire: --propManager.fireBullet; propManager.UpdateDisplay(); break; case Bullet.BulletType.Ice: --propManager.iceBullet; propManager.UpdateDisplay(); break; } //初始化子弹 GameObject bullet = Instantiate(bulletPref, bulletSpawn.position, bulletSpawn.rotation); bullet.GetComponent <Rigidbody2D>().velocity = mouseDir.normalized * speed; }
public void Throw(Vector2 targetDir) { if (bombPref.GetComponent <Thrown>().isSpecial) { if (propManager.specialBomb < 1) { return; } --propManager.specialBomb; propManager.UpdateDisplay(); } else { if (propManager.normalBomb < 1) { return; } --propManager.normalBomb; propManager.UpdateDisplay(); } //播放音效 AudioSource.PlayClipAtPoint(bombsAway, transform.position); //子弹射向目标位置 GameObject bomb = Instantiate(bombPref, transform.position, Quaternion.identity); bomb.GetComponent <Rigidbody2D>().velocity = targetDir.normalized * throwForce * timer; //注册炸弹的爆炸的方法到PlayerController的事件中 if (bomb.GetComponent <Thrown>().isSpecial) { GetComponent <PlayerController>().detonateFunc += bomb.GetComponent <Thrown>().Explode; if (gameObject.tag == "Enemy") { bomb.GetComponent <Thrown>().isPlayer = false; } } timer = 0; }