- Home /
Raycast help!
Hello. I have a RayCast script. It works, but it needs a little touching up. The script is listed below. But my question is, how do I change the Projection from the Mouse pointer to the center of the screen? I'm sorry, I am just starting to learn JavaScript. And I'm 12!!!! Thanks!
function Update(){ if(Input.GetMouseButtonDown(2)){ // if the LEFT button pressed // casts a ray from the mouse pointer var ray = Camera.main.ScreenPointToRay(Input.mousePosition); var hit: RaycastHit; if(Physics.Raycast(ray, hit)){ // if something hit, send the message hit.collider.SendMessageUpwards("ApplyDamage", 20, SendMessageOptions.DontRequireReceiver); } } }
Answer by Berenger · Feb 20, 2012 at 07:44 PM
Camera.ViewportPointToRay(Vector3(0.5, 0.5, 0));
or
Camera.ScreenPointToRay(Vector3(Screen.width * 0.5, Screen.height * 0.5, 0));
YAY!!!! Thanks! Now I need to how to get the LEFT mouse button to fire. But it is co$$anonymous$$g along alright!
Well, that's an easy one, Input.Get$$anonymous$$ouseButtonDown(0) ins$$anonymous$$d of Input.Get$$anonymous$$ouseButtonDown(2) ^^
Thanks again! I totally forgot about that!!!!! I knew this back in 2010, but I haven't even touched unity since early last summer! I've been doing HT$$anonymous$$L! AND I'$$anonymous$$ ONLY 12!!!!!
Don't worry, you're doing great ! Don't give up your social life though, Unity can be a time eater ;)
Ha! Thats true, but I go to cyber school! So... I really don't have anything to do, other than call my friends!
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Raycasting not working as expected 2 Answers
RayCast Problem : 2d 1 Answer
why doesn't this Raycast compare tag work? C# 2 Answers
cant kill more than one enemy C# 2 Answers