- Home /
Question by
shojinLOL · Aug 25, 2017 at 01:58 AM ·
c# to javascript
The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit)' has some invalid arguments
Hi I was converting my script from js and I got this error.
Assets/weapon.cs(49,16): error CS1502: The best overloaded method match for `UnityEngine.Physics.Raycast(UnityEngine.Ray, out UnityEngine.RaycastHit)' has some invalid arguments.
Here is my script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class weapon : MonoBehaviour {
public int dammage = 50;
public float distance;
public float maxdistance = 1.5f;
public Animator animator;
public float damagedelay = 0.6f;
public int hit1streak = 0;
public int hit2streak = 0;
public Ray ray;
// Update is called once per frame
void Update ()
{
if(Input.GetButtonDown ("Fire1"))
{
attackdamage();
}
}
IEnumerator attackdamage()
{
if (Random.value >= 0.5 && hit1streak <= 2) {
animator.SetBool ("Swing01", true);
hit1streak += 1;
hit2streak = 0;
}
else
{
if (hit2streak <= 2) {
animator.SetBool ("Swing02", true);
hit1streak = 0;
hit2streak += 1;
}
else {
animator.SetBool ("Swing01", true);
hit1streak += 1;
hit2streak = 0;
}
}
yield return new WaitForSeconds(damagedelay);
RaycastHit hit;
ray = Camera.main.ScreenPointToRay (new Vector3(Screen.width/2, Screen.height/2,0));
if(Physics.Raycast (ray, hit))
{
distance = hit.distance;
if(distance < maxdistance)
{
hit.transform.SendMessage ("applydammage", dammage, SendMessageOptions.DontRequireReceiver);
}
}
animator.SetBool ("Swing01", false);
animator.SetBool ("Swing02", false);
}
}
Comment
Answer by bobisgod234 · Aug 25, 2017 at 03:00 AM
Change
if(Physics.Raycast (ray, hit))
To
if(Physics.Raycast (ray, out hit))
Your answer
Follow this Question
Related Questions
How to use Android Dual Joysticks? 1 Answer
Making JS Interact with C# Variables 0 Answers
My Health Script Won't work in C# 1 Answer
fade code for c# 2 Answers
Combo Box script from C# to JavaScript 0 Answers