Alexander Sacco
Alexander Sacco

Reputation: 13

unity convert a float to a vector3 c#

Here is my error message:

Assets/BanditLogic.cs(45,30): error CS0029: Cannot implicitly convert type 'float' to 'UnityEngine.Vector3'

And here is a section of the code:

Vector3 Distance = Vector3.Distance (player.transform.position,bandit.transform.position);
anim.SetFloat ("DistanceToPlayer", Distance);

I'm trying to find the distance to the enemy from the player, if there are any easier ways please let me know.

Upvotes: 0

Views: 5142

Answers (1)

oxrock
oxrock

Reputation: 641

You're on the right track. You assigned your variable to a vector3 instead of a float.

float Distance = Vector3.Distance (player.transform.position,bandit.transform.position); 
anim.SetFloat ("DistanceToPlayer", Distance);

this should work

Upvotes: 7

Related Questions