- Home /
Converting Melee Raycast from Java to C# Problems
I had a script written in Javascript for a melee attack system that I want to convert to C# but now I have these errors. Help!
Error CS1620: Argument '3' must be passed with the 'out' keyword (CS1620) (Assembly-CSharp)
Error CS1502: The best overloaded method match for 'UnityEngine.Physics.Raycast(UnityEngine.Vector3, UnityEngine.Vector3, out UnityEngine.RaycastHit)' has some invalid arguments (CS1502) (Assembly-CSharp)
using UnityEngine;
using System.Collections;
public class MeleeSystem : MonoBehaviour {
int Damage = 50;
float Distance;
float MaxDistance = 2;
Transform TheSystem;
void Update (){
if (Input.GetButtonDown("Fire1"))
{
TheSystem.animation.Play("melee_attack");
RaycastHit hit;
if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
{
Distance = hit.distance;
if (Distance < MaxDistance)
hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Answer by robertbu · Mar 12, 2014 at 06:30 AM
The error message is telling you exactly what you need to do. You need to put the 'out' keyowrd before your 'hit' variable:
if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), out hit))
Info on the 'out' keyword:
Your answer
![](https://koobas.hobune.stream/wayback/20220613140035im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Melee system using raycasting 0 Answers
Multiple Cars not working 1 Answer
Create new plane and Raycast in C#? 1 Answer
Player Attack Script. I Need Help! 0 Answers
Raycast collided object not transforming when scripted to? 1 Answer