I'm creating a 2D game and spawn my enemies with Collider 2D
and Rigidbody2D
, and my hero is attacking them, but he casts his attacking ray in strange directions (but mostly if works ok for moving enemies), but it doesn't see static enemies at all! Like I literally can't kill them when I'm in front of them. I guess the problem is in the direction Vector, but I have no idea what I should change
Collider2D enemy= Physics2D.CircleCast(this.transform.position, 2, new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")), 3).collider;
if (enemy.CompareTag("Enemy"))
{
soundSource2.PlayOneShot(slice);
if (enemy.GetComponent<MoveToWayPoints>() != null) // the check of moving enemy
enemy.GetComponent<MoveToWayPoints>().hp.GetComponent<HP>().Dmg(10, 1);
if (enemy.GetComponent<ShamanScript>() != null) // the check of static shaman enemy
{
enemy.GetComponent<ShamanScript>().hp.GetComponent<HP>().Dmg(10, 1);
}
}
MoveToWayPoint
andShamanScript
? Also, is thathp
acts the same in both of the components? \$\endgroup\$MoveToWayPoint
uped to every spawned enemy. It gives them a point where to go, methods how to give a damage and to stop before it and how to be destroyed. Also there is hp object to every enemy, which decreases.ShamanScript
is a script for static enemy shaman, which slow down my hero. It also has hp component. \$\endgroup\$TryGetComponent
instead of null check \$\endgroup\$