Using Raycasts along object axis

I am implementing a simple wind blower which blows wind on mouse click on the object. I used Physics.Raycast to detect the object along the wind path. Debug.draw was used to see how the lines are drawn and test. The script is as follows.

public class BlowingScript : MonoBehaviour {
	
	// Update is called once per frame
	void Update () {
		if(Input.GetMouseButton(0)){

			RaycastHit2D hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint(Input.mousePosition),Vector2.zero);
			if (hit.collider != null) {
				if (hit.collider.CompareTag ("blower")) {
					Debug.Log ("pressed");
					Vector2 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
					transform.position = pos;
		Debug.DrawLine (transform.position ,Vector3.up , new Color(255f,0f,0f));		// a red line
		Debug.DrawLine (transform.position ,transform.forward ,new Color(0f,255f,0f) ); //a green line

				}
			}

		}
	}
}

But in Run mode, the debug lines are like this
109181-untitled.png

what I want to do is to send the ray/line along the transform’s axis (red arrow). But none of the lines are doing it How should my script change? Any comments on the problem, are highly valued.

1 Answer

1

Try using Debug.DrawRay rather than DrawLine?

Either that, or use transform.right, since transform.right is the red arrow. Transform.forward is the blue arrow

Yeah that was the case ! Thank you so much for helping @Wolf402 .