2D Top-Down Shooting Script Errors

Hi guys, still on my way on creating a 2D top-down shooter game. This time I’ve somewhat made a rough script on my players Gun (shooting). However I’m currently getting a lot of error on two lines of codes. They aren’t really using any Vector2’s, I’m quite new to the whole 2D part of Unity I’m more comfortable in 3D. So if anyone can help me out on the errors that would great guys! Thank you so much, this community has helped me heaps :slight_smile:

First error line: The first if function statement
Second error line: The Debug.DrawRay

public class Gun : MonoBehaviour {

public enum GunType {Semi,Burst,Auto}; 
public GunType gunType; 

public Transform spawn; 

public void Shoot () { 

	Ray2D ray = new Ray2D (spawn.position, spawn.forward); 
	RaycastHit2D hit; 

	float shotDistance = 20; 

	if(Physics2D.Raycast(ray,out hit, shotDistance)) { 
		shotDistance = hit.distance; 

	}

	Debug.DrawRay (ray.origin, ray.direction = shotDistance, Color.red, 1);

}

public void ShootContinuous () { 
	if (gunType == GunType.Auto) { 
		Shoot (); 

	} 

} 

}

You are using

ray.direction = shotDistance

Which is false. You probably wanted to do a subtraction operation.