#c# #unity3d
#c# #unity3d
Вопрос:
Проблема в том, что пуля вообще не запускается, когда игрок попадает в диапазон. Вот мой код для атаки
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 не сообщает об ошибке, как и Unity.
Комментарии:
1. Вы можете попробовать поставить
Debug.Log(col.tag)
beforeif (col.CompareTag("Player"))
, чтобы убедиться, что ваш тег правильный. Я подозреваю, что это не так 🙂2. Да, отлаживайте это к чертовой матери — отлаживайте. регистрируйте все и смотрите, где что-то идет не так. Кроме того, если у вашей пули есть OnCollision, проверьте, что она не сталкивается с вещью, которая ее породила, если это так, измените ее слой.