- Home /
RayCast Shooting not working
Hi, I am new to unity this year, and have been having problems with the raycast shooting script. When I play my game, it spawns the effect, but it only spawns in the middle of map. I have had another game without terrain that the raycast worked perfectly. Is terrain the problem? ![alt text][1] Here is my script:
#pragma strict
var Effect : Transform;
var TheDammage = 100;
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
[1]: /storage/temp/35514-raycast+shooting+not+working.png
Hey, how does your actual ray look when shooting in your terrain scene (using Debug.DrawRay)?
Where do I put the Camera.ViewportToRay in? the gun or the camera? How do I use the Debug.DrawRay?
Put it on the camera as this is what you will be ai$$anonymous$$g with(the center of your current viewpoint). It is actually already on it, your are casting from the center of the $$anonymous$$ain Camera object.
For how to use the Debug.DrawRay :
So do I add my draw ray to my camera as well as my raycast shooting script? I have tried using the draw ray on the main camera in the first person controller, but nothing is drawn. The same particle system still spawns in the middle of map using the raycast shooting in the main camera as well.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Very simple inventory script... 0 Answers
Script suddenly stopped working properly 1 Answer
Bullets dont delete properly 1 Answer
each enemy have different damage amount, how to calculate the hp remain??? 1 Answer