- Home /
Question by
abdelrahmanyoussry509 · Aug 07, 2020 at 07:25 AM ·
scripting problemraycastinghow-toask
How Do I See My RayCast?
i am just trying to see my raycast but i dont know how to do it properly cuse i tried to do debug and did not work (i gusse i want it to work with this scpesific script but i dont know how)
yes i am new i know its stuipid question
public GameObject decal;
private float spreadfacotrX = 0.1f;
private float spreadfacotrY = 0.1f;
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
shoot();
}
}
void shoot()
{
//bloom//
Vector3 shootDirection = FindObjectOfType<Motion>().PlayerCam.transform.forward;
if (FindObjectOfType<Gun>().aimed == false)
{
shootDirection.x += Random.Range(-spreadfacotrX, spreadfacotrX);
shootDirection.y += Random.Range(-spreadfacotrY, spreadfacotrY);
}
//end of bloom//
RaycastHit hit;
if (Physics.Raycast(FindObjectOfType<Motion>().PlayerCam.transform.position, shootDirection, out hit,FindObjectOfType<Gun>().loadout[FindObjectOfType<Gun>().invintoryforother].range ))
{
var clonebullet = Instantiate(decal, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(clonebullet, 5);
}
}
}
Comment
Answer by Ymrasu · Aug 07, 2020 at 07:48 AM
Debug.DrawRay is only visible from the Scene view with Gizmos enabled, not the Game view. You can add a duration to the Debug.DrawRay so you can pause right after you shoot so you can see where the ray is being drawn. So you can add this right before your if physics.raycast:
Debug.DrawRay(FindObjectOfType<Motion>().PlayerCam.transform.position, shootDirection * FindObjectOfType<Gun>().loadout[FindObjectOfType<Gun>().invintoryforother].range, Color.green, 2f, false); // visible for 2 seconds
Your answer
![](https://koobas.hobune.stream/wayback/20220613005111im_/https://answers.unity.com/themes/thub/images/avi.jpg)