问题是当玩家进入射程时,子弹根本不会启动。这是我的攻击代码
public void Attack(bool attackingRight)
{
bulletTimer += Time.deltaTime;
if (bulletTimer >= shootInterval)
{
Vector2 direction = target.transform.position - transform.position;
direction.Normalize();
if (!attackingRight)
{
GameObject bulletClone;
bulletClone = Instantiate(bullet, shootPointLeft.transform.position, shootPointLeft.transform.rotation) as GameObject;
bulletClone.GetComponent<Rigidbody2D>().velocity = direction * bulletsSpeed;
bulletTimer = 0;
}
if(attackingRight)
{
GameObject bulletClone;
bulletClone = Instantiate(bullet, shootPointRight.transform.position, shootPointRight.transform.rotation) as GameObject;
bulletClone.GetComponent<Rigidbody2D>().velocity = direction * bulletsSpeed;
bulletTimer = 0;
}
}
这是另一部分
public class Attack_Cone : MonoBehaviour {
public TurretAI turretAI;
public bool isLeft = false;
void Awake()
{
turretAI = gameObject.GetComponentInParent<TurretAI>();
}
void onTriggerStay2D(Collider2D col)
{
if (col.CompareTag("Player"))
{
if (isLeft)
{
turretAI.Attack(false);
}
else
{
turretAI.Attack(true);
}
}
}
无法弄清楚原因。 Visual Studio不会报告错误,因此不会报告错误。