I’m trying to get a raycast to fire from a character sprite on click but for some reason the Debug.DrawLine keeps showing it going to world point 0,0,0 no matter where the character is. Here is the script:
public float fireRate = 0;
public float Damage = 10;
public LayerMask ignoreHit;
public Transform firePoint;
float timeToFire = 0;
void Awake()
{
if (firePoint == null)
{
Debug.LogError("No firepoint");
}
}
void Update()
{
if (fireRate == 0)
{
if (Input.GetButtonDown("Fire1"))
{
Fire();
}
}
else
{
if (Input.GetButton("Fire1") && Time.time > timeToFire)
{
timeToFire = Time.time + 1 / fireRate;
Fire();
}
}
}
void Fire()
{
RaycastHit2D hit = Physics2D.Raycast(firePoint.position, Vector2.right, 100, ignoreHit);
Debug.DrawLine(firePoint.position, hit.point, Color.green);
}
}
Is it the raycast doing this or is the debug line inaccurate?