Hello!
I am making a 2D top down shooter. Right now i am working on the shooting mechanism and decided to go with raycasting. What i want to do is first check so that my ray is going the way i want using Debug.Drawline. I have been trying to figure out how to make a straight line from the fire point to the mouse position for a few hours but i cant figure it out really…
Here is what i have so far:
using UnityEngine;
using System.Collections;
public class Winchester : MonoBehaviour {
private Vector3 firePointPosition;
public Vector3 Mouseposition;
private GameObject firePointObj;
private Transform firePoint;
private float mouseX;
private float mouseY;
void Start ()
{
firePointObj = GameObject.FindGameObjectWithTag ("FirePoint");
firePoint = firePointObj.transform;
}
void Update()
{
mouseX = Input.mousePosition.x;
mouseY = Input.mousePosition.y;
Mouseposition = Camera.main.WorldToScreenPoint (new Vector3(mouseX, mouseY, -10));
firePointPosition = new Vector3 (firePoint.position.x, firePoint.position.y,0);
Debug.DrawLine(firePointPosition,firePointPosition-Mouseposition);
}
}
i now get an infinite line (which is fine) but it follow the mouse movement. Any tips?
Thank you!
/Taegos