The following code produces the error:
if (hitInfo.transform.name == "jumppad" && isJumping == false)
The error is being given because the raycast is not hitting anything such as a collider, it is just going out into open space.
This is the error that is showing up:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gun_script : MonoBehaviour
{
public Transform firepoint;
public LineRenderer linerend;
public Transform gun;
public float mouseSens;
public int jumpHeight = 5;
float lookangle;
public Rigidbody2D rbForPlayer;
Vector2 lookDirection;
private bool isJumping = false;
// Update is called once per frame
void Update()
{
isJumping = false;
lookDirection = Camera.main.WorldToScreenPoint(Input.mousePosition);
lookangle = Mathf.Atan2(lookDirection.y, lookDirection.x) * Mathf.Rad2Deg;
gun.rotation = Quaternion.Euler(0, 0, lookangle * mouseSens);
RaycastHit2D hitInfo = Physics2D.Raycast(firepoint.position, firepoint.right);
if (hitInfo)
{
linerend.SetPosition(0, firepoint.position);
linerend.SetPosition(1, hitInfo.point);
}
else
{
linerend.SetPosition(0, firepoint.position);
linerend.SetPosition(1, firepoint.position + firepoint.right * 100);
}
if (hitInfo.transform.name == "jumppad" && isJumping == false)
{
Invoke("Jump", 1f);
}
}
void Jump()
{
isJumping = true;
rbForPlayer.AddForce(new Vector2(0, jumpHeight));
}
}