public class Gun : MonoBehaviour
{
public Ray ray;
public RaycastHit hit;
public GameObject enemy;
void Update ()
{
Debug.DrawRay(transform.position,transform.forward*400,Color.red);
ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width*0.5f,Screen.height*0.5f,0));
if(Input.GetMouseButtonDown(0))
{
if(Physics.Raycast(ray,transform.forward*10f,100.0f))
{
EnemyHealth eh =(EnemyHealth)enemy.GetComponent("EnemyHealth");
eh.ApplyD();
}
}
}
}
and the unity wrote me:
Assets/Scripts/Gun.cs(17,36): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, float, int)’ has some invalid arguments
Assets/Scripts/Gun.cs(17,36): error CS1503: Argument #2' cannot convert UnityEngine.Vector3’ expression to type `float’
Assets/Scripts/Gun.cs(20,36): error CS1501: No overload for method ApplyD' takes 0’ arguments
and I try to find the problem but dont find any
can someone pls help me?
thx
as the error says, there isn’t a version of the raycast function that takes the parameters you are trying to give it… what is that raycast supposed to be doing?
the last one… I assume “ApplyD” is a version of the ApplyDamage function used in the send message examples? in which case it probably takes a parameter of how much damage to apply. Again, you’re not giving the function the parameters it is expecting.
Since you already have a ray as a first parameter you don’t need a direction as a second parameter. Just remove it and keep 2 params - ray and distance.