- Home /
Question by
caprariualex · Jan 10, 2020 at 07:28 PM ·
object2d-platformerenemyshootraycasthit2d
Raycast2D enemy and player problem
Hi guys! I have a problem. I'm begginer, don't judge me please. 7 hours to make a raycast to detect a player and a "wall". I can't make the enemy raycasted player and object.(coordonates)[PK= Tag of Player; Tp= you know it] Any helps please? My problem is: RaycastHit2D hit = Physics2D.Raycast(firePoint.position, Tp.position, Mathf.Infinity); (positions and stuff)
void Update() { if (GameObject.FindGameObjectWithTag("PK") != null) { Tp = GameObject.FindGameObjectWithTag("PK").GetComponent();
RaycastHit2D hit = Physics2D.Raycast(firePoint.position, Tp.position, Mathf.Infinity);
if (hit.collider != null)
{
if (hit.collider.gameObject.tag != "Ground")
{
Debug.DrawRay(firePoint.position, Tp.position, Color.green);
Debug.Log(hit.collider);
if (Time.time > timeToFire)
{
CheckIfTimeToFire();
}
}
}
}
}
Comment