- Home /
Duplicate Question
AttackDammage errors
There were some errors on this code
void AttackDammage (){
//Attack function
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
if (Physics.Raycast (ray, hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
{
hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
How can I fix these errors? CS0103: The name `ray' does not exist in the current context UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3)' has some invalid arguments
Answer by robertbu · Oct 07, 2014 at 04:32 AM
You have not declared the 'ray'. Change line 4 to:
Ray ray = Camera.main.ScreenPointToRay(Vector3(Screen.width/2, Screen.height/2, 0));
This should get rid of the two errors listed in your question.
There's 2 more errors
error CS1502: The best overloaded method match for UnityEngine.Camera.ScreenPointToRay(UnityEngine.Vector3)' has some invalid arguments error CS1620: Argument
#2' is missing `out' modifier
There's another error
UnityEngine.Vector3 is a type but used like a variable
Follow this Question
Related Questions
Is it possible to check how much a trigger is filled by %? 1 Answer
c# How do I set up continuous raycast collision detection? 1 Answer
Raycast Mouse Click On Specific Objects Only 0 Answers
Creating 2d image map of objects based off 3d space colliders Unity C# 0 Answers
How to Find Owner of a Trigger? 1 Answer