- Home /
Vector3 Distance Incompatibility
Hi! Whilst writing code for a Melee system for my game I came across an error that I can't fix. The error is as follows: "The Best overload for the method 'UnityEngine.Vector3.Distance(UnityEngine.Vector3, UnityEngine.Vector3)' is not compatible with the argument list '(UnityEngine.Vector3)'."7
My code on the line of complaint: var dist = Vector3.Distance(hit.transform.position - transform.position);
Answer by Kiwasi · Jul 11, 2014 at 09:20 PM
Correct code to do this is
var dist = Vector3.Distance(hit.transform.position, transform.position);
You can also use
var dist = (hit.transform.position, transform.position).magnitude;
You should also do some googling to understand arguments, overloading and methods. This is pretty essential stuff to know if you plan to code.
Its also one of the easiest errors to fix yourself.
Your answer
Follow this Question
Related Questions
3 vector3 distance checks, only one works 1 Answer
GameObject's transform in Vector3 1 Answer
on collision damage 1 Answer
BurgZergArcade tutorial 5 problem 1 Answer